By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,812 Members | 856 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,812 IT Pros & Developers. It's quick & easy.

$_SESSION variable not carrying

P: n/a
Greetings,
I am trying to do some simple session stuff. However it does not seem
as though the session variable is being created for my site. I am
running the latest version of PHP and apache that I installed as part
of WAMP. Machine is XP SP2.

Basically I am trying to do something simple such as:

<?php

// initialize a session
session_start();

// increment a session counter
$_SESSION['counter']++;

// print value
echo "You have viewed this page " . $_SESSION['counter'] . " times";

?>

However my counter does not increment. I can also not see where any
sort of cookie has been created within IE, although firefox shows the
following:

Name: PHPSESSID
Content: 4s0n98f1s7jea6kg11psi4ckd3
Host: 10.0.0.15
Path: /
Send for: Any type of connection
Expires: at end of session

I am not sure about the Path: variable though. The address for my site
is 10.0.0.15/recipe

physical is C:\wamp\www\recipe

Here are some of the contents of my php.ini file:

[Session]
session.save_handler = files

session.save_path = "C:\Windows\temp "

session.use_cookies = 1

session.name = PHPSESSID

session.auto_start = 0

session.cookie_lifetime = 0

session.cookie_path = /

session.cookie_domain =

Any suggestions would be greatly appreciated!

Jul 18 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"dp*****@gmail.com" <dp*****@gmail.comwrote in
news:11*********************@x35g2000prf.googlegro ups.com:
Greetings,
I am trying to do some simple session stuff. However it does not seem
as though the session variable is being created for my site. I am
running the latest version of PHP and apache that I installed as part
of WAMP. Machine is XP SP2.

Basically I am trying to do something simple such as:

<?php

// initialize a session
session_start();

// increment a session counter
$_SESSION['counter']++;

// print value
echo "You have viewed this page " . $_SESSION['counter'] . " times";
you don't see your new session/cookie value until you call it from the
NEXT/FOLLOWING page.

Also, this might make more sense:
$_SESSION['counter'] = $_SESSION['counter']++;
Jul 18 '07 #2

P: n/a
Good Man wrote:
"dp*****@gmail.com" <dp*****@gmail.comwrote in
news:11*********************@x35g2000prf.googlegro ups.com:
>Greetings,
I am trying to do some simple session stuff. However it does not seem
as though the session variable is being created for my site. I am
running the latest version of PHP and apache that I installed as part
of WAMP. Machine is XP SP2.

Basically I am trying to do something simple such as:

<?php

// initialize a session
session_start();

// increment a session counter
$_SESSION['counter']++;
First of all, never use uninitialized variables. Even if you think
this is o.k. if(!isset($_SESSION['counter'])) $_SESSION['counter']=0; is
not hard code but now you don't depend of session vars behavior modified
with every PHP version.
>// print value
echo "You have viewed this page " . $_SESSION['counter'] . " times";

you don't see your new session/cookie value until you call it from the
NEXT/FOLLOWING page.

Also, this might make more sense:
$_SESSION['counter'] = $_SESSION['counter']++;
Will never increment it because of post-increment.

I think you mean this:
$_SESSION['counter'] = $_SESSION['counter']+1;
Jul 19 '07 #3

P: n/a
Alexey Kulentsov wrote:
Good Man wrote:
>"dp*****@gmail.com" <dp*****@gmail.comwrote in
news:11*********************@x35g2000prf.googlegr oups.com:
>>Greetings,
I am trying to do some simple session stuff. However it does not seem
as though the session variable is being created for my site. I am
running the latest version of PHP and apache that I installed as part
of WAMP. Machine is XP SP2.

Basically I am trying to do something simple such as:

<?php

// initialize a session
session_start();

// increment a session counter
$_SESSION['counter']++;

First of all, never use uninitialized variables. Even if you think this
is o.k. if(!isset($_SESSION['counter'])) $_SESSION['counter']=0; is not
hard code but now you don't depend of session vars behavior modified
with every PHP version.
>>// print value
echo "You have viewed this page " . $_SESSION['counter'] . " times";

you don't see your new session/cookie value until you call it from the
NEXT/FOLLOWING page.

Also, this might make more sense:
$_SESSION['counter'] = $_SESSION['counter']++;
Will never increment it because of post-increment.

I think you mean this:
$_SESSION['counter'] = $_SESSION['counter']+1;
Or, just

$_SESSION['counter']++;

$_SESSION['counter'] = $_SESSION['counter']++;

is an "undefined operation" - it could contain the old value or the new
value. Either result could be considered "legal".

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 19 '07 #4

P: n/a
dp*****@gmail.com wrote:
session.save_path = "C:\Windows\temp "
Is that space character inside the path really there? If so, remove it.

Also, try using "/" instead of "\" in the path -- backslashes are used in
PHP strings to escape special characters. In particular, your path
contains "\t" which PHP may treat as a tab character!

Lastly, if you're using NTFS (you don't specify) check which user Apache is
running as, and make sure that the Temp folder is writable by that user.
To be sure, you could try giving "Full Control" on the Temp folder to
"Everyone". (I think that's the terminology used in XP.)

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 29 days, 15:47.]

Parsing an HTML Table with PEAR's XML_HTTPSax3
http://tobyinkster.co.uk/blog/2007/0...table-parsing/
Jul 20 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.