Session Variables

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
mickey
-


Joined: 09 Dec 2002
Posts: 25

PostPosted: Thu Mar 13, 2003 2:10 pm    Post subject: Session Variables Reply with quote

I am having problems with session variables I have tried many ways to solve this, and have posted to quite a few sites for help. I have now concluded that the code is correct and that my php.ini file is set correctly, but still they don't work properly.

I was asked to try this little test :
Quote:

Load up your page with the session_start() function on and then load up another page to display phpinfo(), if the cookie is being set there will be a variable listed in the PHP variables section called _SERVER["HTTP_COOKIE"] containg the value PHPSESSID=(some 32 digit value) if not your session cookie is not being set properly.

which i did and have discovered that I do not have _SERVER["HTTP_COOKIE"] listed in my php.ini file, and that this may be the root of my problem

I have also been told that the server may not be sending out the cookie information.

Does anyone know how I could go about fixing it? Is there maybe something on the web server that I should tweek to get it to send out the correct cookie info?


I am trying to run the following code:
Code:

<?php
session_start();
session_register('count');
$_SESSION[count]++;

$msg = "<p>You've been here $_SESSION[count] times.  Thanks! </p>";
?>

<html>
<head>
<title>
Count Me
</title>
</head>
<body>
<a href="<?php echo $_SERVER['PHP_SELF'] ?>">Click Here</a>
<? echo "$msg"; ?>
</body>
</html>


the number is supposed to increment but it doesn't. The message is displayed perfectly in the browser though. been struggling with this for a long time now, any ideas please :?:
Back to top View user's profile Send private message
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Thu Mar 13, 2003 8:32 pm    Post subject: Re: Session Variables Reply with quote

The server does not distinguish betwwen cookies and other info it sends to the CGI script. By the way, we tested you script, and it works perfectly on our computer. So please check your browser (it seems that it isn't sending the cookirs correctly, try lowering its security level) or your firewall (some of them filter cookies).
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
mickey
-


Joined: 09 Dec 2002
Posts: 25

PostPosted: Thu Mar 13, 2003 11:36 pm    Post subject: Thank You!, Thank You!, Thank You!... Reply with quote

Thank You!, Thank You!, Thank You!... :D

Aprelium to the rescue again. You were right of course, it was the browsers security level, all is working fine now.

thanks agin,
mickey
Back to top View user's profile Send private message
mickey
-


Joined: 09 Dec 2002
Posts: 25

PostPosted: Sun Mar 16, 2003 1:51 pm    Post subject: Spoke too soon... Reply with quote

Spoke too soon...my session variables are not working fine....I have another problem. The script that I posted above will only increment if I click on the second link:
Code:
 <a href="<?php echo $_SERVER['PHP_SELF'] ?>">Click Here</a>

just clicking on the browsers refresh button alone doesn't increment the counter. But after having clicked on the above link the browsers refresh will then start to work.

does this mean anything to anyone? As it means nothing to me. I know from what Aprelium and others have said that it must be a browser problem but I don't know what else to try.

I do have a firewall on my computer and have turned this off, I have tried in three different browsers, IE, Netscape and Opera, and it doesn't work correctly in any of them. I have also looked at the settings in all of the mentioned browsers in relation to security, I couldn't find anything to change in NS and Opera, In IE I have turned down the security levels so that they are on medium-low and this seems to make no difference. (I tried setting this to low, but it doesn't keep the setting for some reason.)

To be honest this script is not my main problem, but the same reason that I can't get this script to work is the same reason that I a having problems with certain parts of my other session scripts. So any help that anyone can give is greatly appreciated.
Back to top View user's profile Send private message
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Sun Mar 16, 2003 8:17 pm    Post subject: Re: Spoke too soon... Reply with quote

Refreshing a page doesn't mean that your browser gets it from the web server again. It may take it from its cache. So all depends on how your browser caching policy is configured. You can say to the browser to not cache a page by adding this PHP code in the very beginning of a script:
Code:

header("Cache-Control: no-store, no-cache, must-revalidate");  // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");                          // HTTP/1.0

_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
mickey
-


Joined: 09 Dec 2002
Posts: 25

PostPosted: Mon Mar 17, 2003 5:37 pm    Post subject: Reply with quote

I tried your code and it didn't make a difference.

After I click on the 'Click Here' link within the page the browsers refresh button starts to work on its own, if the problem was with caching why would this be?
Back to top View user's profile Send private message
jabi
-


Joined: 17 Mar 2003
Posts: 17
Location: Florida, US

PostPosted: Mon Mar 17, 2003 8:23 pm    Post subject: Reply with quote

I just joined the forum and was looking for help when I saw your post. I'm not an expert by any means... just happen to have been trying to solve a similar problem myself lately.

Added one line to your script - to initialize the count variable - and changed the variable from $_SESSION[count] to $count. That seemed to fix it, at least on my system. It now increments when either using the link or the "refresh" button. (Compacted the html for easier viewing in forum.)

<?php
session_start();
session_register('count');
if(empty($count)) $count = 0;
$count++;
$msg = "<p>You've been here $count times. Thanks! </p>";
?>

<html> <head> <title> Count Me </title> </head>
<body>
<a href="<?php echo $_SERVER['PHP_SELF'] ?>">Click Here</a>
<? echo "$msg"; ?>
</body> </html>

Joan
[url]globallifeguards.org[/url]
Back to top View user's profile Send private message
mickey
-


Joined: 09 Dec 2002
Posts: 25

PostPosted: Tue Mar 18, 2003 10:27 am    Post subject: Reply with quote

Thanks for that jabi, I tried your code in three browsers, but this doesn't work either. :cry:
Back to top View user's profile Send private message
jabi
-


Joined: 17 Mar 2003
Posts: 17
Location: Florida, US

PostPosted: Tue Mar 18, 2003 11:30 am    Post subject: Reply with quote

Looked at your other posts and saw some of your php.ini settings. When I first set up php on my windows machine, I couldn't get the sessions to work until I created a /tmp directory, and then used the following settings:
session.save_path = C:/tmp
session.cookie_path = /
session.cookie_domain =

Jabi
[url]globallifeguards.org[/url]
Back to top View user's profile Send private message
mickey
-


Joined: 09 Dec 2002
Posts: 25

PostPosted: Tue Mar 18, 2003 6:37 pm    Post subject: Reply with quote

:lol: jabi you are brilliant!...

Looks like that was the problem and all "seems" to be working fine now!!! I only hope that it stays that way, php seems to be a little temperamental.

Thank You so much for your help, it's been very much appreciated.

Mickey
Back to top View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group