> Date: Wed, 15 Apr 2009 11:09:19 -0500
> From: awill...@mdah.state.ms.us
> To: php-general@lists.php.net
> Subject: [PHP] header() and passing sessions
> 
> I need some help passing a session variable with a header() function. 
> According to www.php.net/header, the documentation states:
> 
> *Note*: Session ID is not passed with Location header even if 
> session.use_trans_sid 
> <session.configuration.php#ini.session.use-trans-sid> is enabled. It 
> must by passed manually using *SID* constant.
> 
> so, I'm trying to manually pass the SID, but not having any luck. Here 
> is a snippet of my code:
> 
> There is a file login.php which has session_start(); and sets 
> $_SESSION["username"] with the username you logged in with from 
> index.php and has a form to click View Pending Requests which has the 
> action of option.php.
> 
> -- option.php --
> <?php
> session_start();
> if ($_POST["option"] == "View Pending Requests")
> {
> header('Location: 
> http://intra.mdah.state.ms.us/helpdesk/viewpending.php?PHPSESSID='.session_id());
> }
> ?>
> 
> --viewpending.php --
> <?php
> session_start();
> if (!$_SESSION["username"])
> {
> echo "You have not logged in";
> exit;
> }
> ?>
> 
> so you click on View Pending Requests, and the URL in your browser is:
> 
> http://intra.mdah.state.ms.us/helpdesk/viewpending.php?PHPSESSID=du75p41hel9k1vpuah799l2ce7
> 
> but viewpending.php says "You have not logged in". Why is that?

 

Hi,

Well I'ld say the reason is quite obvious. You have simply not set 
$_session["username"] . I'ld have done something like:

 

-- option.php --
<?php
 session_start();
 if ($_POST["option"] == "View Pending Requests")
{

$_session["username"]= true;  //sets the session
 header('Location: 
 http://intra.mdah.state.ms.us/helpdesk/viewpending.php?PHPSESSID='.SID);    // 
I'ld use SID
 } 
 ?>


 

--viewpending.php -
 <?php
 session_start();
 if ($_SESSION["username"] !=true)
 {
 echo "You have not logged in";
 exit;
 }
 ?>

 

I hope this helps. try it.

Cheers

Alugo Abdulazeez



_________________________________________________________________
Drag n’ drop—Get easy photo sharing with Windows Live™ Photos.

http://www.microsoft.com/windows/windowslive/products/photos.aspx

Reply via email to