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 11, 2007 7:17 PM UTC
Excellent - that's how to do it! Thanks for the hints!

--
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
==================


"Michael Fesser" <netizen@gmx.de> wrote in message
news:6fntl3tn7qm6ldcph5jpmt855s58nj4as1@4ax.com...
> .oO(Murray *ACE*)
>
>>Host has already fixed it. Nice service!
>
> Great.
>
> Just for completeness: In order to use your own directory for session
> storage, you just create it where you're allowed to and pass the full
> path to session_save_path().
>
> In my own session handler I define a path constant, which is based on
> $_SERVER['DOCUMENT_ROOT'] and contains the full path to the directory
> where I want my session data to be. Then I simply let my script check if
> the directory exists and create it if necessary:
>
> ...
> if (!file_exists(EMLIB_APP_SESSION_PATH)) {
> mkdir(EMLIB_APP_SESSION_PATH, 0700, TRUE);
> }
> ini_set('session.auto_start', 0);
> ini_set('session.use_cookies', 0);
> ini_set('session.use_trans_sid', 0);
> session_save_path(EMLIB_APP_SESSION_PATH);
> ...
>
> Micha

Translate
Inspiring
Dec 11, 2007 7:05 PM UTC
.oO(Murray *ACE*)

>Host has already fixed it. Nice service!

Great.

Just for completeness: In order to use your own directory for session
storage, you just create it where you're allowed to and pass the full
path to session_save_path().

In my own session handler I define a path constant, which is based on
$_SERVER['DOCUMENT_ROOT'] and contains the full path to the directory
where I want my session data to be. Then I simply let my script check if
the directory exists and create it if necessary:

...
if (!file_exists(EMLIB_APP_SESSION_PATH)) {
mkdir(EMLIB_APP_SESSION_PATH, 0700, TRUE);
}
ini_set('session.auto_start', 0);
ini_set('session.use_cookies', 0);
ini_set('session.use_trans_sid', 0);
session_save_path(EMLIB_APP_SESSION_PATH);
...

Micha
Translate
Inspiring
Dec 11, 2007 6:47 PM UTC
Host has already fixed it. Nice service!

--
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
==================


"Michael Fesser" <netizen@gmx.de> wrote in message
news:26ltl3te6otn0fmvbngv47d0hohv4b8ecl@4ax.com...
> .oO(Murray *ACE*)
>
>>It's not my own server, unfortunately.
>
> No problem. But you should still be able to create a directory in your
> own home directory, set write permissions for the web server and call
> session_save_path() to use that directory for your session data.
>
> In my own projects I always have a directory /var outside of the
> document root with full write access for the web server. There my
> scripts can store session data, error logs and such things.
>
> Micha

Translate
Inspiring
Dec 11, 2007 6:35 PM UTC
How would I path to that location?

--
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
==================


"Michael Fesser" <netizen@gmx.de> wrote in message
news:26ltl3te6otn0fmvbngv47d0hohv4b8ecl@4ax.com...
> .oO(Murray *ACE*)
>
>>It's not my own server, unfortunately.
>
> No problem. But you should still be able to create a directory in your
> own home directory, set write permissions for the web server and call
> session_save_path() to use that directory for your session data.
>
> In my own projects I always have a directory /var outside of the
> document root with full write access for the web server. There my
> scripts can store session data, error logs and such things.
>
> Micha

Translate
Inspiring
Dec 11, 2007 6:32 PM UTC
It's that simple?

--
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
==================


"Michael Fesser" <netizen@gmx.de> wrote in message
news:26ltl3te6otn0fmvbngv47d0hohv4b8ecl@4ax.com...
> .oO(Murray *ACE*)
>
>>It's not my own server, unfortunately.
>
> No problem. But you should still be able to create a directory in your
> own home directory, set write permissions for the web server and call
> session_save_path() to use that directory for your session data.
>
> In my own projects I always have a directory /var outside of the
> document root with full write access for the web server. There my
> scripts can store session data, error logs and such things.
>
> Micha

Translate
Inspiring
Dec 11, 2007 6:22 PM UTC
.oO(Murray *ACE*)

>It's not my own server, unfortunately.

No problem. But you should still be able to create a directory in your
own home directory, set write permissions for the web server and call
session_save_path() to use that directory for your session data.

In my own projects I always have a directory /var outside of the
document root with full write access for the web server. There my
scripts can store session data, error logs and such things.

Micha
Translate
Inspiring
Dec 11, 2007 6:10 PM UTC
It's not my own server, unfortunately. I'll contact the host....

Thanks for sticking with me on this to all of you. I'll post the results
when I get them.

--
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
==================


"Michael Fesser" <netizen@gmx.de> wrote in message
news:pvjtl3phuiucsse6gebn254gi4nul3f01m@4ax.com...
> .oO(Murray *ACE*)
>
>>Thanks, David - looks like that has uncovered something (this from the
>>test-session2.php page) -
>>
>>Warning: session_start() [function.session-start]:
>>open(/var/lib/php/session/vservers/squarewheeli/tmp/sess_t9e4u778e1pmnfaqp80g72j9d4,
>>O_RDWR) failed: Permission denied (13) in
>>/vservers/squarewheeli/htdocs/test-session2.php on line 4
>
> This explains a lot. The web server is not allowed to store the session
> file on disk. Usually you want to change the session directory to
> something below your own home directory, where you can then set the
> required permissions. See session_save_path(). Or try to change the
> permissions of the directory above if this should be your own server.
>
> Micha

Translate
Inspiring
Dec 11, 2007 6:03 PM UTC
.oO(Murray *ACE*)

>Thanks, David - looks like that has uncovered something (this from the
>test-session2.php page) -
>
>Warning: session_start() [function.session-start]:
>open(/var/lib/php/session/vservers/squarewheeli/tmp/sess_t9e4u778e1pmnfaqp80g72j9d4,
>O_RDWR) failed: Permission denied (13) in
>/vservers/squarewheeli/htdocs/test-session2.php on line 4

This explains a lot. The web server is not allowed to store the session
file on disk. Usually you want to change the session directory to
something below your own home directory, where you can then set the
required permissions. See session_save_path(). Or try to change the
permissions of the directory above if this should be your own server.

Micha
Translate
Inspiring
Dec 11, 2007 5:46 PM UTC
Thanks, David - looks like that has uncovered something (this from the
test-session2.php page) -

Warning: session_start() [function.session-start]:
open(/var/lib/php/session/vservers/squarewheeli/tmp/sess_t9e4u778e1pmnfaqp80g72j9d4,
O_RDWR) failed: Permission denied (13) in
/vservers/squarewheeli/htdocs/test-session2.php on line 4

Click

Warning: Unknown:
open(/var/lib/php/session/vservers/squarewheeli/tmp/sess_t9e4u778e1pmnfaqp80g72j9d4,
O_RDWR) failed: Permission denied (13) in Unknown on line 0

Warning: Unknown: Failed to write session data (files). Please verify that
the current setting of session.save_path is correct
(/var/lib/php/session/vservers/squarewheeli/tmp) in Unknown on line 0

And then, when I click, this from the subsequent page -

Warning: session_start() [function.session-start]:
open(/var/lib/php/session/vservers/squarewheeli/tmp/sess_t9e4u778e1pmnfaqp80g72j9d4,
O_RDWR) failed: Permission denied (13) in
/vservers/squarewheeli/htdocs/test-session2b.php on line 4

The session variable has a value of -
Notice: Undefined index: usertype in
/vservers/squarewheeli/htdocs/test-session2b.php on line 19

Warning: Unknown:
open(/var/lib/php/session/vservers/squarewheeli/tmp/sess_t9e4u778e1pmnfaqp80g72j9d4,
O_RDWR) failed: Permission denied (13) in Unknown on line 0

Warning: Unknown: Failed to write session data (files). Please verify that
the current setting of session.save_path is correct
(/var/lib/php/session/vservers/squarewheeli/tmp) in Unknown on line 0

--
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
==================


"David Powers" <david@example.com> wrote in message
news:fjmddh$c4d$1@forums.macromedia.com...
> Murray *ACE* wrote:
>> And those two pages work!
>
> Sessions obviously work. However, your server has display_errors turned
> off. It's possible that there's a control character or whitespace before
> the call to session_start(). Put this at the very top of both pages:
>
> <?php ini_set('display_errors', '1'); ?>
>
> See if you get any error messages.
>
> --
> David Powers, Adobe Community Expert
> Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
> Author, "PHP Solutions" (friends of ED)
> http://foundationphp.com/

Translate
Inspiring
Dec 11, 2007 5:14 PM UTC
On Mon, 10 Dec 2007 17:53:13 -0500, "Murray *ACE*"
<forums@HAHAgreat-web-sights.com> wrote:

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

Can you make copies of both pages with a .txt extension and upload
those? If that would expose sensitive information, e-mail them to me if
you want and I'll look deeper.

Gary
Translate