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
https://forums.phpfreaks.com/topic/175649-how-to-pass-a-session-to-another-page/
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.

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 ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.