bugzy Posted April 3, 2012 Share Posted April 3, 2012 Hello I have this login page with code <?php header("Expires: Thu, 17 May 2001 10:17:17 GMT"); // Date in the past header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header ("Pragma: no-cache"); // HTTP/1.0 session_start(); //Below means if session database server crdentials is not set, require to use/set that connection then if (!isset($_SESSION['SESSION'])) require ( "../db_connection.php"); if($_SESSION['LOGGEDIN'] == TRUE) { header("Location: account.php"); exit; } $_SESSION['FORM_SUBMITTED'] = ""; $CRLF = chr(13).chr(10); $user_id = ""; if (isset($HTTP_GET_VARS["user_id"])) $user_id = $HTTP_GET_VARS["user_id"]; if ($user_id == '') { if (isset($_SESSION['user_id'])) $user_id = $_SESSION['user_id']; } //Validations $flg = ""; $error = ""; if (isset($HTTP_GET_VARS["flg"])) $flg = $HTTP_GET_VARS["flg"]; switch ($flg) { case "yellow": $error = "<font class=\"txt_main_str12_mar\"><BR>Your Account Has Not Been Verified.<BR>Check your email for Activation Instructions.<br>Click <a href=\"/courses/forgot_login.php\">here</a> to have the activation email resent.</font>"; break; case "red": $error = "<font class=\"txt_main_str12_mar\"><BR>That userid/password combination is not in our database.<br>Please Try Again.</font>"; break; case "blue": $error = "<font class=\"txt_main_str12_mar\"><BR>Your Session has Expired.<br>Please Login Again.</font>"; break; default: $error = " <br>"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Login Page</title> <script language="JavaScript"> <!-- function loadedPage() { } function submitForm() { if (isEmpty(document.forms[0].user_id.value)) { alert("Please enter your UserID."); bSubmit = false; return false; } if (isEmpty(document.forms[0].password.value)) { alert("Please enter your Password."); bSubmit = false; return false; } document.forms[0].submit(); } //--> </script> </head> <body><center><br /><br /> <form name="form1" method="post" id="form1" action="/php/sessions/login/login_processing.php"> <table> <tr> <td>User ID</td> <td><input type="text" name="user_id" id="user_id" value="<?php echo $user_id ?>" size="24" maxlength="30" /></td> </tr> <tr> <td>Password</td> <td><input type="password" name="password" id="password" size="24" maxlength="30" /></td> </tr> <tr> <td> </td> <td><input type="submit" name="Submit" value="Submit" onclick="submitForm();" /></td> </tr> </table> </form> </center> </body> </html> and login processing page with code <?php header("Expires: Thu, 17 May 2001 10:17:17 GMT"); // Date in the past header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header ("Pragma: no-cache"); // HTTP/1.0 session_start(); //Below means if session database server crdentials is not set, require to use/set that connection then if (!isset($_SESSION['SESSION'])) require ( "../db_connection.php"); // reset session variables... $_SESSION['user_id'] = ""; $_SESSION['LOGGEDIN'] = false; $_SESSION['EMAIL'] = ""; $_SESSION['FNAME'] = ""; $_SESSION['LNAME'] = ""; // initialize variables... $user_id = ""; $password = ""; $email = ""; // make sure post parameters were sent... if (isset($HTTP_POST_VARS["user_id"])) $user_id = addslashes($HTTP_POST_VARS["user_id"]); if (isset($HTTP_POST_VARS["password"])) $passwd = addslashes($HTTP_POST_VARS["password"]); $_SESSION['user_id'] = $user_id; // form variables must have something in them... if ($user_id == "" || $password == "") { header("Location: ./login_page.php?flg=yellow&user_id=".$user_id); exit; } ?> I'm having problem with the last piece of code above, it's redirecting me eventhough I have entered a value on the userid and password from the login page... Quote Link to comment https://forums.phpfreaks.com/topic/260299-cant-pass-variables-to-a-page/ Share on other sites More sharing options...
batwimp Posted April 3, 2012 Share Posted April 3, 2012 You set your $user_id to a blank string, then you assign that blank string to the session variable, then check to see if it's set. You may have meant to do this instead: $user_id = $_SESSION['user_id']; Quote Link to comment https://forums.phpfreaks.com/topic/260299-cant-pass-variables-to-a-page/#findComment-1334172 Share on other sites More sharing options...
bugzy Posted April 3, 2012 Author Share Posted April 3, 2012 You set your $user_id to a blank string, then you assign that blank string to the session variable, then check to see if it's set. You may have meant to do this instead: $user_id = $_SESSION['user_id']; Tried it and used isset It's telling me that it is set but it's not passing the values that I have entered from the previous page. I tried to echo it and it's still not getting the values.. What do you think is the problem? Quote Link to comment https://forums.phpfreaks.com/topic/260299-cant-pass-variables-to-a-page/#findComment-1334176 Share on other sites More sharing options...
batwimp Posted April 3, 2012 Share Posted April 3, 2012 Where are you putting the information into the session variable? Quote Link to comment https://forums.phpfreaks.com/topic/260299-cant-pass-variables-to-a-page/#findComment-1334178 Share on other sites More sharing options...
bugzy Posted April 3, 2012 Author Share Posted April 3, 2012 Where are you putting the information into the session variable? Hey thank you very much. I'm just new in php and I'm not sure if we're on the same page here.. but I'm putting the information on the login page where I have "username" and "password" you can actually see that on the 1st code that I posted. I'm supposed to be getting the variables using this if (isset($HTTP_POST_VARS["user_id"])) $user_id = addslashes($HTTP_POST_VARS["user_id"]); if (isset($HTTP_POST_VARS["password"])) $passwd = addslashes($HTTP_POST_VARS["password"]); Though the problem is I'm not getting anything.... Quote Link to comment https://forums.phpfreaks.com/topic/260299-cant-pass-variables-to-a-page/#findComment-1334186 Share on other sites More sharing options...
batwimp Posted April 4, 2012 Share Posted April 4, 2012 OK. Sorry about that. Your original line of code was correct. I'm not used to seeing $HTTP_POST_VARS, and my brain sort of just flew past that. Change it back to the way it was and I will start over trying to figure out what it's doing. Somewhere just after you assign the $user_id to your session variable, echo out your session variable to see if it's holding anything: echo "User id: ".$_SESSION['user_id']."<br />"; Quote Link to comment https://forums.phpfreaks.com/topic/260299-cant-pass-variables-to-a-page/#findComment-1334215 Share on other sites More sharing options...
bugzy Posted April 4, 2012 Author Share Posted April 4, 2012 OK. Sorry about that. Your original line of code was correct. I'm not used to seeing $HTTP_POST_VARS, and my brain sort of just flew past that. Change it back to the way it was and I will start over trying to figure out what it's doing. Somewhere just after you assign the $user_id to your session variable, echo out your session variable to see if it's holding anything: echo "User id: ".$_SESSION['user_id']."<br />"; Hey thank you very much! I have used this instead $_SESSION['user_id'] = $user_id; $_SESSION['password'] = $password; and it seemed like I'm now getting the user_id and password. My problem now is on this thread... http://www.phpfreaks.com/forums/index.php?topic=357088.0 Quote Link to comment https://forums.phpfreaks.com/topic/260299-cant-pass-variables-to-a-page/#findComment-1334274 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.