0

I'm very new to PHP... and have a REST api which sets a session var when a user signs in:

$a = session_id();
if(empty($a)) session_start();
$_SESSION['id']=...

When I call a testFunction in the same browser (anoter tab) the session var is still the same:

$sessionID = session_id();
if(empty($sessionID)) session_start();
echo($_SESSION['id']);

When I Later open an iframe on the page it's still fine.

BUT, when the page inside the iframe reloads to another url, the session is lost...

$_SESSION['id'] // gives error: Undefined index: id

That is, I'm always staying on the same page but my iframe is changing urls.

Am I missunderstanding php session vars? Am I missusing it? Both?

4

2 回答 2

0

你也需要调用session_start()iframe 代码,你真的在​​调用它吗?

于 2012-10-18T12:15:38.470 回答
0

You need to call session_start() whenever you are using session. You don't need to check session_id().

session_start() creates a session or resumes the current one based on a session identifier passed via a GET or POST request, or passed via a cookie.

于 2012-10-18T12:18:18.967 回答