Jump to content

How to pass a session to another page?


samoi

Recommended Posts

Hello guys!

I have this example of login.php page:

<?
// login.php script!

$SQL = mysql_query(" a query ");
$row = mysql_fetch_row($SQL);

if(mysql_num_rows($row)){ // login ok ... set vars and redirect to users.php page!

session_start();
$_SESSION["user"] = $row[1];
$_SESSION["email"] = $row[4];
// .... etc vars!
header("location: users.php");

}
else{
// wrong login info
}
?>

 

 

user.php script as follow:

<?
session_start();
include('header.php'); ### this script has a session_start() function too!

if(isset($_SESSION["user"])){

// welcome

}
else{
header("location: login.php");
}
?>

 

 

BUT: when I login with correct info. it says "A session had already been started - ignoring session_start() in login.php"

 

 

how to pass the session in all pages and let it work as it was set in the login page!?

Link to comment
Share on other sites

You only need to start the session once, in your login page. The session info will pass through to all your pages itself, you shouldn't need to do anything else.

Wrong, session_start() must be placed on every page that you wish to access the super-global $_SESSION.

Link to comment
Share on other sites

You only need to start the session once, in your login page. The session info will pass through to all your pages itself, you shouldn't need to do anything else.

Wrong, session_start() must be placed on every page that you wish to access the super-global $_SESSION.

 

Yes, this is true. I always put it in header.php so I forget about it right away ;)

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.