login  Naam:   Wachtwoord: 
Registreer je!
 Forum

Session-variable werkt niet overal

Offline webstab - 22/12/2005 09:55
Avatar van webstabPHP ver gevorderde Eventjes de situatie schetsen. (Je hebt niet iedere file nodig, maar dat weet je hoe het ineen zit)
.htaccess
  1. RewriteEngine On
  2. RewriteCond %{REQUEST_FILENAME} !-f
  3. RewriteRule ^[^/]* /modrewrite.php?page=$0

modrewrite.php
  1. <?php
  2. include_once ('config.php');
  3. if((Isset($_GET['page']) AND $_GET['page'] == "index") or empty($_GET['page'])) {
  4. include ('index.php');
  5. } elseif((Isset($_GET['page']) AND $_GET['page'] == "register")) {
  6. include ('register.php');
  7. } elseif((Isset($_GET['page']) AND $_GET['page'] == "login")) {
  8. include ('login.php');
  9. } elseif((Isset($_GET['page']) AND $_GET['page'] == "logout")) {
  10. include ('logout.php');
  11. } elseif((Isset($_GET['page']) AND $_GET['page'] == "cpanel")) {
  12. $des = explode("/", $_SERVER['REQUEST_URI']);
  13. $_GET['action'] = $des[2];
  14. include ('cpanel.php');
  15. } elseif((Isset($_GET['page']) AND $_GET['page'] == "activate")) {
  16. $des = explode("/", $_SERVER['REQUEST_URI']);
  17. $_GET['user'] = $des[2];
  18. include ('activate.php');
  19. } elseif (Isset($_GET['page'])) {
  20. $des = explode("/", $_SERVER['REQUEST_URI']);
  21. $_GET['action'] = $des[2];
  22. $_GET['user'] = $_GET['page'];
  23. include ('checkprofile.php');
  24. } else {
  25. include ('404.php');
  26. } ?>

config.php (enkel database connectie)
login.php
  1. <?php
  2. function form($error,$user,$pass) {
  3. return "<form action=\"\" method=\"post\">
  4. <font color=\"red\">".$error."</font>
  5. <table border=\"0\"><tr><td>
  6. Gebruikersnaam:</td><td><input type=\"text\" name=\"user\" value=\"".$user."\"></td></tr><tr><td>
  7. Wachtwoord:</td><td><input type=\"password\" name=\"pass\" value=\"".$pass."\"></td></tr>
  8. <tr><td colspan=\"2\"><input type=\"checkbox\" name=\"public\">&nbsp;<small>Ik gebruik een openbare computer</small>
  9. <br><a href=\"\">Wachtwoord vergeten?</a></td></tr>
  10. <tr><td></td><td><input type=\"submit\" name=\"login\" value=\"Login\"></td></tr>
  11. </table>
  12. </form>\n";
  13. }
  14. if (Isset($_POST['login'])) {
  15. $lquery = mysql_query("SELECT * FROM members WHERE name='" . $_POST['user'] . "'") or die(mysql_error());
  16. $laquery = mysql_query("SELECT * FROM members WHERE name='" . $_POST['user'] . "' AND activate='0'") or die(mysql_error());
  17. $cuser = mysql_fetch_array($lquery);
  18. if (mysql_num_rows($lquery) == "0") { echo form("Gebruikersnaam is niet correct!","",""); }
  19. elseif (mysql_num_rows($laquery) == "1") { echo form("Uw account is nog niet geactiveerd!","",""); }
  20. elseif(strcmp(md5($_POST['pass']), $cuser['password'])) { echo form("Uw wachtwoord is niet correct!",$_POST['user'],""); }
  21. else {
  22. $_SESSION['userid'] = $cuser['id'];
  23. if (empty($_POST['public']) or $_POST['public'] == 0 or $_POST['public'] == "OFF") {
  24. Setcookie("username", $_POST['user'], Time() + 60 * 60 * 24 * 365);
  25. Setcookie("userpass", $_POST['pass'], Time() + 60 * 60 * 24 * 365);
  26. }
  27. Header("location: /cpanel");
  28. }
  29. } elseif (Isset($_COOKIE['userpass']) AND Isset($_COOKIE['username'])) {
  30. $lquery = mysql_query("SELECT * FROM members WHERE name='".$_COOKIE['username']."'") or die(mysql_error());
  31. $cuser = mysql_fetch_array($lquery);
  32. if(strcmp(md5($_COOKIE['userpass']), $cuser['password'])) { echo form("Uw wachtwoord is niet correct!",$_COOKIE['user'],""); }
  33. else {
  34. $_SESSION['userid'] = $cuser['id'];
  35. Header("location: /cpanel");
  36. }
  37. } else {
  38. echo form("","","");
  39. } ?>

cpanel.php
  1. <?php
  2. if (Isset($_GET['action'])) {
  3. switch ($_GET['action']) {
  4. case "changepassword": include ('changepassword.php'); break;
  5. default: include ('cpanelhome.php'); break;
  6. }
  7. } else {
  8. include ('cpanelhome.php');
  9. }
  10. ?>

changepassword.php
  1. <?php
  2. function form($error) {
  3. return "<form name=\"FormName\" action=\"\" method=\"post\">
  4. <font color=\"red\">".$error."</font><br>
  5. Uw oud wachtwoord:&nbsp;<input type=\"password\" name=\"passo\" value=\"\"><br><br>
  6. Uw nieuw wachtwoord:&nbsp;<input type=\"password\" name=\"pass\" value=\"\"><br><br>
  7. Uw nieuw wachtwoord:&nbsp;<input type=\"password\" name=\"pass2\" value=\"\">&nbsp;<small>(opnieuw)</small><br><br>
  8. <input type=\"submit\" name=\"submit\" value=\"Wijzig mijn paswoord\">
  9. </form>\n";
  10. }
  11. if (Isset($_POST['submit']) && Isset($_POST['passo'])) {
  12. $passo = md5($_POST['passo']);
  13. $sqlcheck = "SELECT * FROM members WHERE id='".$_SESSION['userid']."' AND password='".$wachto."'";
  14. $querycheck = mysql_query($sqlcheck) or die (mysql_error());
  15. $correctcheck = mysql_num_rows($querycheck);
  16. if ($correctcheck == "1") {
  17. if ($_POST['pass'] == $_POST['pass2']) {
  18. $pass = md5($_POST['pass']);
  19. mysql_query("UPDATE members SET password='".$pass."' WHERE id='".$_SESSION['userid']."'") or die(mysql_error());
  20. echo "Je wachtwoord is succesvol gewijzigd.<a href=\"/cpanel\">Terug naar controlepaneel</a>";
  21. } else {
  22. echo form("Uw wachtwoorden komen niet overeen.");
  23. }
  24. } else {
  25. echo form("Uw oud wachtwoord is niet correct.");
  26. }
  27. } else {
  28. echo form("");
  29. }
  30. ?>

Maar in changepassword /cpanel/changepassword wordt de session['userid'] niet weergegeven. Wanneer ik een echo doe, doet hij niets.
Maar bij cpanel(home) /cpanel doet hij dat wel. Hoe kan dit?

PS: Sorry voor de lappen code, maar ik dacht dat je met een stuk niets bent

0 antwoorden

Gesponsorde links
Er zijn nog geen reacties op dit bericht.
Dit onderwerp is gesloten.
Actieve forumberichten
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.246s