Graham Cossey wrote:

I'm having a bad day with sessions which hopefully someone can help me with.

A user logs in to my 'site' (script1.php) and I store relevant details in a
session, all fine. I redirect to another page (script2.php) which checks and
retrieves certain session values, all fine. My problem is with script3.php
which happens to be within an iframe in script2.php. When the user is
automatically passed to that page, from log in, the session details are not
available but if the user makes a (menu) selection the session values are
available to script3.php within the iframe. help !

Simplified code:

script1.php
<?php
  session_start();
  [some code]
  $_SESSION['user'] = $_POST['user'];
  [some code]
  $hdr = "Location: script2.php?".SID;
  header($hdr);
?>

script2.php
<?php
  session_start();
  if (!isset($_SESSION['user']))
      Header("Location: ../index.htm"); << Does not redirect.
  [some code]
  <iframe name="content" src="script3.php">
    Your browser does not support the use of frames.
  </ifame>
  [some code]
?>

script3.php
<?php
  session_start();
  print_r($_SESSION); << outputs Array()
  [some code]
?>

If you need any specific info on my config just ask and I'll try and supply
it.

You need to use full URLs in your header() redirects, first of all.

header('Location: http://www.example.org/script2.php?".SID);

Is a session cookie being set at all? You redirect to script2 and pass the SID in the URL, so that's why the session persists. You're not passing the SID in the URL for the source of the iframe leading to script3, so the script doesn't know what session to pick up.

Try: <iframe name="content" src="script3.php?<?=SID?>">

--

---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals – www.phparch.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to