frijole Posted May 28, 2008 Share Posted May 28, 2008 I am still working on my login script. I am trying to get the username of the person who signed to display on the front page that the form redirects to. I have a <?php echo $_SESSION['userName']; ?> on the front page. But, nothing is displayed. I can't tell why. <?php ob_start(); // buffer the output require_once 'dbConnect.php'; require_once 'functions.php'; $error = ''; if ($_POST['logIn'] == 1) { //if the form has been submitted $userName = $_POST['user']; $pass = $_POST['pass']; $query = "SELECT * FROM users WHERE user_name='$userName' AND user_pass='$pass'"; $result = mysql_query($query) or die("connection error."); if (empty($userName) || empty($pass)) { //are any of the fields empty $error = "All fields must be filled out.";} elseif (mysql_num_rows($result) != 1) { //if the username and password combo are not valid $error = "Invalid username, password combo.";} else { //log in was successful if (keepLogged ==1) { $year = 525600 + time(); setcookie(thinksnack, 1, $year); } $_SESSION['userName'] = $userName; $_SESSION['loggedIn'] = 1; header('Location: http://www.thinksnack.com/index.php'); } } showLogInForm ($error); ob_end_flush(); // dump the buffer ?> Link to comment https://forums.phpfreaks.com/topic/107573-solved-session-variables-not-being-transferred-to-new-page/ Share on other sites More sharing options...
peranha Posted May 28, 2008 Share Posted May 28, 2008 do you have session_start(); on the first page It needs to be the first line on the page after <?php ex <?php session_start(); ?> Link to comment https://forums.phpfreaks.com/topic/107573-solved-session-variables-not-being-transferred-to-new-page/#findComment-551386 Share on other sites More sharing options...
frijole Posted May 28, 2008 Author Share Posted May 28, 2008 thanks, that did it. Link to comment https://forums.phpfreaks.com/topic/107573-solved-session-variables-not-being-transferred-to-new-page/#findComment-551388 Share on other sites More sharing options...
peranha Posted May 28, 2008 Share Posted May 28, 2008 remember hit topic solved when a topic is finished and no further help is needed. Thanks Link to comment https://forums.phpfreaks.com/topic/107573-solved-session-variables-not-being-transferred-to-new-page/#findComment-551390 Share on other sites More sharing options...
frijole Posted May 28, 2008 Author Share Posted May 28, 2008 sorry, that feature was disabled last time i was on the site. Thanks again. Link to comment https://forums.phpfreaks.com/topic/107573-solved-session-variables-not-being-transferred-to-new-page/#findComment-551402 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.