Shazbot! Posted June 19, 2007 Share Posted June 19, 2007 Just a quick question that I hope someone here can answer. I created a login in screen that once a user is identified a Session is created for them, then I transfer them to the authorized page. However, when I use header('location:http://www.someurl.com'); to transfer them to that page the Session does not go with them. I fixed this problem by inserting a javascript that redirects them but would prefer to use php. Any help/suggesions would be helpful...thanks! Link to comment https://forums.phpfreaks.com/topic/56201-creating-a-session/ Share on other sites More sharing options...
Dragen Posted June 19, 2007 Share Posted June 19, 2007 a session always stays with them. You need to have session_start(); at the top of every page using sessions. Link to comment https://forums.phpfreaks.com/topic/56201-creating-a-session/#findComment-277575 Share on other sites More sharing options...
Shazbot! Posted June 20, 2007 Author Share Posted June 20, 2007 yep, I have session_start(); at the top of the page and it is a post back to the same page. Once validation is done it calls the function to redirect the user. Link to comment https://forums.phpfreaks.com/topic/56201-creating-a-session/#findComment-278524 Share on other sites More sharing options...
trq Posted June 20, 2007 Share Posted June 20, 2007 Post some relevent code. Link to comment https://forums.phpfreaks.com/topic/56201-creating-a-session/#findComment-278526 Share on other sites More sharing options...
Dragen Posted June 20, 2007 Share Posted June 20, 2007 yep, I have session_start(); at the top of the page and it is a post back to the same page. Once validation is done it calls the function to redirect the user. Do you mean you only have session_start() on the first page? sorry if I missunderstood, but you need session_start() on the page you're re-directing to as well. Link to comment https://forums.phpfreaks.com/topic/56201-creating-a-session/#findComment-278528 Share on other sites More sharing options...
cluce Posted June 20, 2007 Share Posted June 20, 2007 you should have session_start() on the top of every page where you are passing session variables. Link to comment https://forums.phpfreaks.com/topic/56201-creating-a-session/#findComment-278555 Share on other sites More sharing options...
Shazbot! Posted June 22, 2007 Author Share Posted June 22, 2007 Here is the code that I have. Please note that I have only been working with PHP since last Sept. Thank you for taking the time to look at this. login page session_start(); if(isset($_SESSION['SEC_LEVEL'])) { header('location:URL.php'); }//end if //some code and HTML if(isset($_POST['Submit'])) { //validate form VerifyStudent(txtName, txtPassword]); } //end if function VerifyStudent($UserName, $Password) { global $error; if($_POST['txtPosition']==1) { //student login } else { //staff login }//end if $SQL_Query=mssql_query($SQL); $User=mssql_fetch_row($SQL_Query); if(mssql_num_rows($SQL_Query)!=0) { $_SESSION['SEC_LEVEL'] = $User[0]; $_SESSION['ACCTID'] = $User[1]; $_SESSION['USER'] = $User[2]." ".$User[3]; ?> <script language="javascript"> window.location='URL/Menu.php'; </script> <?php //header('location:URL/Menu.php'); } else { array_push($error, "Invalid Username and Password"); }//end if menu.php //this is at the top of page require_once('../inc/Determine_Session.php'); Determine_Session.php //this is at the top of the page session_start(); if(!isset($_SESSION['SEC_LEVEL'])) { header('location:URL/login.php'); }//end if Link to comment https://forums.phpfreaks.com/topic/56201-creating-a-session/#findComment-280342 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.