Jump to content

Creating a session


Shazbot!

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.