Jump to content


Photo

problem with session_start()


  • Please log in to reply
15 replies to this topic

#1 dckarina

dckarina
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 06 June 2006 - 07:48 AM

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.


#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 06 June 2006 - 08:10 AM

Are you sure cookies are enabled in your browser?

#3 dckarina

dckarina
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 06 June 2006 - 09:29 AM

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.

#4 dckarina

dckarina
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 06 June 2006 - 01:30 PM

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

#5 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 06 June 2006 - 01:46 PM

Maybe it's a IE6 bug.
Try to add a header:

header("Cache-control: private");

Right after session_start()
~ D Kuang

#6 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 06 June 2006 - 02:53 PM

What web server? I've heard the IIS has problems with sessions.

Ken

#7 dckarina

dckarina
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 06 June 2006 - 03:39 PM

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

header("Cache-control: private");

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) View Post[/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

#8 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 06 June 2006 - 03:53 PM

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 same client machine and browser then there's a problem with your server-side scripting.

It may be worth testing performance with the same client machine running different browsers.
Legend has it that reading the manual never killed anyone.
My site

#9 dckarina

dckarina
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 06 June 2006 - 04:07 PM

[!--quoteo(post=380637:date=Jun 6 2006, 06:53 PM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ Jun 6 2006, 06:53 PM) View Post[/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 same client machine and browser then there's a problem with your server-side scripting.

It may 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

#10 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 06 June 2006 - 05:02 PM

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

#11 dckarina

dckarina
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 06 June 2006 - 06:05 PM

[!--quoteo(post=380665:date=Jun 6 2006, 08:02 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Jun 6 2006, 08:02 PM) View Post[/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

#12 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 06 June 2006 - 06:41 PM

I run xampp on my laptop.

Create a php script named info.php in a directory you use for your scripts which contains:
<?php
p.hpinfo();
?>
(remove the period from p.hpinfo)
Invoke the script via a browser and look for the line that starts "Configuration File (php.ini) Path". 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

#13 dckarina

dckarina
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 06 June 2006 - 07:13 PM

[!--quoteo(post=380721:date=Jun 6 2006, 09:41 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Jun 6 2006, 09:41 PM) View Post[/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:
<?php
p.hpinfo();
?>
(remove the period from p.hpinfo)
Invoke the script via a browser and look for the line that starts "Configuration File (php.ini) Path". 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.

#14 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 07 June 2006 - 03:53 AM

so..you can't rightclick > properties > change it from read only to writeable?
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#15 Ferenc

Ferenc
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts

Posted 07 June 2006 - 06:18 AM

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]

Everything you want to know is here.

#16 dckarina

dckarina
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 07 June 2006 - 07:05 AM

[!--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) View Post[/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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users