Jump to content

Archived

This topic is now archived and is closed to further replies.

dckarina

problem with session_start()

Recommended Posts

when i use session_start() it creates a new session even if i have already opened a session. i have 2 php files.
<?php
session_start();
echo session_id();
echo "<a href=page2.php>next page</a>"
?>

page2.php

<?php
session_start();
echo session_id();
?>

the session id is different for each file.
please help me.

Share this post


Link to post
Share on other sites
Are you sure cookies are enabled in your browser?

Share this post


Link to post
Share on other sites
yes,i'm sure. i checked. and on some computers it works ok but on others it doesn't.and i used mozilla on all.

Share this post


Link to post
Share on other sites
no idea why this is happening?i really need this so i can work on my own computer. so any ideas may be usefull
Karina

Share this post


Link to post
Share on other sites
Maybe it's a IE6 bug.
Try to add a header:

[code]header("Cache-control: private");[/code]

Right after session_start()

Share this post


Link to post
Share on other sites
What web server? I've heard the IIS has problems with sessions.

Ken

Share this post


Link to post
Share on other sites
[!--quoteo(post=380597:date=Jun 6 2006, 04:46 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Jun 6 2006, 04:46 PM) [snapback]380597[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Maybe it's a IE6 bug.
Try to add a header:

[code]header("Cache-control: private");[/code]

Right after session_start()
[/quote]

i added that too.still not working.10x anyway
karina


[!--quoteo(post=380621:date=Jun 6 2006, 05:53 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Jun 6 2006, 05:53 PM) [snapback]380621[/snapback][/div][div class=\'quotemain\'][!--quotec--]
What web server? I've heard the IIS has problems with sessions.

Ken
[/quote]

I use XAMPP.it has Apache and Mysql.But i have XAMPP where I work and there I have no problems with sessions. I didn't have to configure anything, I just had to install it. It's the same version but for some reason on another computer i have problems with sessions.
Karina

Share this post


Link to post
Share on other sites
If this works perfectly when accessed from 'some' computers and doesn't work when accessed from 'other' computers, then I would assume initially that the problem lies with the client machine browser/browser settings and not that there's a problem with the server or server-side coding.

That said, the fact that a client-side set-up can adversely affect your server-side coding's performance suggests you need to adjust the server-side code to compensate for the client-side differences (because those are sure to crop up over and over again and you can't exert any sensible control over client preferences).

If it works some of the time and fails some of the time using the [b]same[/b] client machine and browser then there's a problem with your server-side scripting.

It [i]may[/i] be worth testing performance with the same client machine running different browsers.

Share this post


Link to post
Share on other sites
[!--quoteo(post=380637:date=Jun 6 2006, 06:53 PM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ Jun 6 2006, 06:53 PM) [snapback]380637[/snapback][/div][div class=\'quotemain\'][!--quotec--]
If this works perfectly when accessed from 'some' computers and doesn't work when accessed from 'other' computers, then I would assume initially that the problem lies with the client machine browser/browser settings and not that there's a problem with the server or server-side coding.

That said, the fact that a client-side set-up can adversely affect your server-side coding's performance suggests you need to adjust the server-side code to compensate for the client-side differences (because those are sure to crop up over and over again and you can't exert any sensible control over client preferences).

If it works some of the time and fails some of the time using the [b]same[/b] client machine and browser then there's a problem with your server-side scripting.

It [i]may[/i] be worth testing performance with the same client machine running different browsers.
[/quote]

i used IE and Mozilla on the same computer. The same result. I'm out of ideas.
Karina

Share this post


Link to post
Share on other sites
Take a look in the PHP.INI file. Make sure the directory that the session manager wants to use is really there and is writable.

Ken

Share this post


Link to post
Share on other sites
[!--quoteo(post=380665:date=Jun 6 2006, 08:02 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Jun 6 2006, 08:02 PM) [snapback]380665[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Take a look in the PHP.INI file. Make sure the directory that the session manager wants to use is really there and is writable.

Ken
[/quote]

what exactly i'm looking for? what session. ...?
i don't really know how to configure php.ini. I have xampp. I only had to install
Karina

Share this post


Link to post
Share on other sites
I run xampp on my laptop.

Create a php script named info.php in a directory you use for your scripts which contains:
[code]<?php
p.hpinfo();
?>[/code]
(remove the period from p.hpinfo)
Invoke the script via a browser and look for the line that starts "[b]Configuration File (php.ini) Path[/b]". On my display it is the sixth line. Note the value in the right column. That value on my machine is "C:\Program Files\xampp\apache\bin\php.ini"

Open that file in notepad or your favorite editor and look for the line that starts with "session.save_path". There should be a directory there. Check that the directory exists and is not marked "read only".

Ken

Share this post


Link to post
Share on other sites
[!--quoteo(post=380721:date=Jun 6 2006, 09:41 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Jun 6 2006, 09:41 PM) [snapback]380721[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I run xampp on my laptop.

Create a php script named info.php in a directory you use for your scripts which contains:
[code]<?php
p.hpinfo();
?>[/code]
(remove the period from p.hpinfo)
Invoke the script via a browser and look for the line that starts "[b]Configuration File (php.ini) Path[/b]". On my display it is the sixth line. Note the value in the right column. That value on my machine is "C:\Program Files\xampp\apache\bin\php.ini"

Open that file in notepad or your favorite editor and look for the line that starts with "session.save_path". There should be a directory there. Check that the directory exists and is not marked "read only".

Ken
[/quote]
the directory exists but it's marked read-only. what should i do? i'm using wamp server now if it helps
there is a session.save_handler=files and it says something that windows user should modify it but i don't
really understand how.

Share this post


Link to post
Share on other sites
You are making this more of a pain than it needs to be.

sessions, and all other things you want a server to store are saved in /tmp (/temp) by default (if it exists).


if not defined in the php.ini, php looks to the defaut temp dirdectory(/temp..../tmp)

Windows temp directory is C:\Documents and Settings\USER_NAME\Local Settings\Temp
the problem with windows....apache doesn't have access. This is a good thing!

You can adjust things so the user stores ther session via a cookie, but that isn't always possible....or wise

Simply edit the session store path directory in the php.in to C:/temp
then make the folder temp in C:\


read more [a href=\"http://us2.php.net/manual/da/ref.session.php\" target=\"_blank\"]here[/a]

Share this post


Link to post
Share on other sites
[!--quoteo(post=380853:date=Jun 7 2006, 06:53 AM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ Jun 7 2006, 06:53 AM) [snapback]380853[/snapback][/div][div class=\'quotemain\'][!--quotec--]
so..you can't rightclick > properties > change it from read only to writeable?
[/quote]

no.i can't change it. but i don't think that is the problem. i tried it on another computer which has the same path and the directory is the same - read-only- but it works, it doesn't create a new session when i click the link

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.