Skip to main content
Inspiring
Dec 10, 2007 9:36 PM UTC
Question

Session variables - what's up?

I have a page with this markup -

<?php

session_start();

$_SESSION['usertype'] = 2;

header("Location: s_support-repair-parts.php");
exit();

?>

The page redirects to a new page containing this markup -

<?php session_start(); ?>
...
<?php
echo "User is type: " . $_SESSION['usertype'];
...
?>

I never see a value echoed - what's up with that?

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


This topic is closed to new replies. Start a new post to keep the conversation going.

30 replies

Inspiring
Dec 10, 2007 10:56 PM UTC


--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


"Massimo Foti" <massimo@massimocorner.com> wrote in message
news:fjkem0$40b$1@forums.macromedia.com...
> "Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
> news:fjkecd$3on$1@forums.macromedia.com...
>> Which FF tool will show me request headers?
>
> I use this:
> http://livehttpheaders.mozdev.org/

Cool - OK, I'll grab it.

>
>
>
>> I am seeing a cookie for the session called PHPSESSID, and its value is
>> the same on all the pages involved, but I am not seeing any other
>> cookie....
>
> If the value for PHPSESSID is the same the session should persist.
>
> Is any session working on your test server?

Yes. I have other code (from David Powers) that is working!

FILE1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Session test 1</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="test2-session2.php">
<p>
<label for="name">Name:</label>
<input type="text" name="name" id="name" />
</p>
<p>
<input type="submit" name="button" id="button" value="Submit" />
</p>
</form>
</body>
</html>


FILE2

<?php
// initiate session
session_start();
// check that form has been submitted and that name is not empty
if ($_POST && !empty($_POST['name'])) {
// set session variable
$_SESSION['name'] = $_POST['name'];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Session test 2</title>
</head>

<body>
<?php
// check session variable is set
if (isset($_SESSION['name'])) {
//if set, greet by name
echo 'Hi, '.$_SESSION['name'].'. <a href="session3.php">Next</a>';
}
else {
// if not set, send back to login
echo 'Who are you? <a href="session1.php">Login</a>';
}
?>
</body>
</html>

Admittedly, it's not the same thing, since this is reading the value from
$_POST, but it is working.

> Have you tried the same code on another server?

No.

>
> Massimo
>

Translate
Inspiring
Dec 10, 2007 10:53 PM UTC
> Works for me. On the page you're re-directing to, is the session_start()
> at the beginning of the file?
>
> <?php
> session_start();
> ?>
> <!DOCTYPE ...
>
> The session_start() call must appear before any content is sent to the
> browser.

Yes. It's right at the start of the page.

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


"Gary White" <reply@newsgroup.please> wrote in message
news:1mfrl39m8cdjhaqqgafmvqm9a7r5fo28ip@4ax.com...
> On Mon, 10 Dec 2007 16:36:13 -0500, "Murray *ACE*"
> <forums@HAHAgreat-web-sights.com> wrote:
>
>>I never see a value echoed - what's up with that?
>
> Works for me. On the page you're re-directing to, is the session_start()
> at the beginning of the file?
>
> <?php
> session_start();
> ?>
> <!DOCTYPE ...
>
> The session_start() call must appear before any content is sent to the
> browser.
>
> Gary

Translate
Inspiring
Dec 10, 2007 10:35 PM UTC
On Mon, 10 Dec 2007 16:36:13 -0500, "Murray *ACE*"
<forums@HAHAgreat-web-sights.com> wrote:

>I never see a value echoed - what's up with that?

Works for me. On the page you're re-directing to, is the session_start()
at the beginning of the file?

<?php
session_start();
?>
<!DOCTYPE ...

The session_start() call must appear before any content is sent to the
browser.

Gary
Translate
Inspiring
Dec 10, 2007 10:30 PM UTC
"Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
news:fjkecd$3on$1@forums.macromedia.com...
> Which FF tool will show me request headers?

I use this:
http://livehttpheaders.mozdev.org/



> I am seeing a cookie for the session called PHPSESSID, and its value is
> the same on all the pages involved, but I am not seeing any other
> cookie....

If the value for PHPSESSID is the same the session should persist.

Is any session working on your test server?
Have you tried the same code on another server?

Massimo


Translate
Inspiring
Dec 10, 2007 10:25 PM UTC
Massimo - cookies are enabled in both IE7 and FF2x.

Which FF tool will show me request headers?

I am seeing a cookie for the session called PHPSESSID, and its value is the
same on all the pages involved, but I am not seeing any other cookie....

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


"Massimo Foti" <massimo@massimocorner.com> wrote in message
news:fjkdr8$35v$1@forums.macromedia.com...
> "Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
> news:fjkd56$2d7$1@forums.macromedia.com...
>>> A quick look at the cookies or the HTTP headers could help
>>
>> The headers for the linked page are these -
>
> You have to look at the values of the cookies sent by the browsers, either
> by looking at the HTTP Request headers (not the response you posted) or
> the tools available in FF (plus the ones added by many extensions).
>
> If I remember well, the session identifier cookie in PHP should be named:
> "PHPSESSID". The value for it must be the same accross different requests
> in order for the session to persist
>
> BTW Have you checked your browser is set to accept cookies?
>
> Massimo
>

Translate
Inspiring
Dec 10, 2007 10:16 PM UTC
"Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
news:fjkd56$2d7$1@forums.macromedia.com...
>> A quick look at the cookies or the HTTP headers could help
>
> The headers for the linked page are these -

You have to look at the values of the cookies sent by the browsers, either
by looking at the HTTP Request headers (not the response you posted) or the
tools available in FF (plus the ones added by many extensions).

If I remember well, the session identifier cookie in PHP should be named:
"PHPSESSID". The value for it must be the same accross different requests in
order for the session to persist

BTW Have you checked your browser is set to accept cookies?

Massimo


Translate
Inspiring
Dec 10, 2007 10:04 PM UTC
> Is the redirect preventing any cookie to be set

If I replace the redirect with a link to the other page, and click on the
link, the results are the same.

> A quick look at the cookies or the HTTP headers could help

The headers for the linked page are these -

Date: Mon, 10 Dec 2007 20:59:29 GMT
Server: Apache/2.2.3 (Red Hat) mod_fastcgi/2.4.2 DAV/2 mod_ssl/2.2.3
OpenSSL/0.9.8b SVN/1.4.2
X-Powered-By: PHP/5.1.6
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0,
pre-check=0
Pragma: no-cache
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8

200 OK

Not sure what to look for there.
--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


"Massimo Foti" <massimo@massimocorner.com> wrote in message
news:fjkcbs$1h5$1@forums.macromedia.com...
>I haven't used PHP in the last few years, so I am just wild guessing, since
>I am not sure how PHP handles redirects and cookies these days.
>
> Is the redirect preventing any cookie to be set, including the one used to
> identify the session?
> A quick look at the cookies or the HTTP headers could help
>
> --
> ----------------------------
> Massimo Foti, web-programmer for hire
> Tools for ColdFusion and Dreamweaver developers:
> http://www.massimocorner.com
> ----------------------------
>
>

Translate
Inspiring
Dec 10, 2007 9:55 PM UTC
Thanks, Massimo - I'll check it out....

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


"Massimo Foti" <massimo@massimocorner.com> wrote in message
news:fjkcbs$1h5$1@forums.macromedia.com...
>I haven't used PHP in the last few years, so I am just wild guessing, since
>I am not sure how PHP handles redirects and cookies these days.
>
> Is the redirect preventing any cookie to be set, including the one used to
> identify the session?
> A quick look at the cookies or the HTTP headers could help
>
> --
> ----------------------------
> Massimo Foti, web-programmer for hire
> Tools for ColdFusion and Dreamweaver developers:
> http://www.massimocorner.com
> ----------------------------
>
>

Translate
Inspiring
Dec 10, 2007 9:50 PM UTC
I haven't used PHP in the last few years, so I am just wild guessing, since
I am not sure how PHP handles redirects and cookies these days.

Is the redirect preventing any cookie to be set, including the one used to
identify the session?
A quick look at the cookies or the HTTP headers could help

--
----------------------------
Massimo Foti, web-programmer for hire
Tools for ColdFusion and Dreamweaver developers:
http://www.massimocorner.com
----------------------------


Translate