jmr3460 Posted July 11, 2009 Share Posted July 11, 2009 I am trying to call a session value that was set on previous page. (Set_sessions.php) <?php ini_set ("display_errors", "1"); error_reporting(E_ALL);if ((empty($_POST['username'])) && (empty($_POST['password']))) { header("Location: index.php"); exit(); } elseif ((!isset($_POST['username'])) && (!isset($_POST['password']))) { header("Location: index.php"); exit(); } //testing for admin user elseif ((isset($_POST['username'])) && (isset($_POST['password']))) { //id names of database and table to use $db_name = "arscnaor_groupinfo"; //connect to server and select database $connection = @mysql_connect("localhost", "user", "password") or die(mysql_error()); $db = @mysql_select_db($db_name, $connection) or die(mysql_error()); //build and issue ADMIN query $sql = "SELECT * FROM admin WHERE username = \"$_POST[username]\" AND password = password(\"$_POST[password]\")"; $result = @mysql_query($sql) or die (mysql_error()); //get the number of rows in the result set $num = mysql_numrows($result); $id = mysql_fetch_array($result); //set a cookie and print display if authorized, //or redirect elsewhere if unauthorized if ($num != 0) { session_start(); $_SESSION['admin_id'] = $id['id']; $_SESSION['admin_user'] = $id['username']; header("Location: admin_updates.php"); exit(); } elseif ((isset($_POST['username'])) && (isset($_POST['password']))); { //build and issue GROUP query $sql = "SELECT * FROM auth_users WHERE username = \"$_POST[username]\" AND password = password(\"$_POST[password]\")"; $result = @mysql_query($sql) or die (mysql_error()); //get the number of rows in the result set $num = mysql_numrows($result); $id = mysql_fetch_array($result); //set a cookie and print display if authorized, //or redirect elsewhere if unauthorized if ($num != 0) { session_start(); $_SESSION['group_id'] = $id['id']; $_SESSION['group_user'] = $id['username']; header("Location: group_updates.php"); exit(); } } } ?> I am directed to the proper pages. I think that my opening if statemant is rediredting me back to my index.php page and I do not know why. This is my php block: <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); if (!isset($_SESSION['admin_user'])) { header("Location: index.php"); exit; } ?> This is my first Sessions script. I can echo session value from the session_set.php page. Why is it redirecting me back to the index page? I read this script to say "If $_SESSION['admin_user'] is not set then run the header(). I know the value is set I can echo it from the previous page. What am I missing? Link to comment https://forums.phpfreaks.com/topic/165576-solved-_session-question/ Share on other sites More sharing options...
jmr3460 Posted July 11, 2009 Author Share Posted July 11, 2009 Sorry I missed my 10 minute time limit. I found the problem on another post. I did not know that I need to session_start(); on every page. I learned something else today. Thanks for the views. Link to comment https://forums.phpfreaks.com/topic/165576-solved-_session-question/#findComment-873375 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.