Page 1 of 1
Loosing Session when clicking a link (a href)...
Posted: Sun Jun 01, 2008 4:22 pm
by razer.anthom
Hi all.
I am having a weird problem with PHP sessions. I create a session but when I click a link inside my site, other session is created. To test it I copy this code below and tried to run in same environment (WAMP at localhost). The same behavior was presented. Sometimes, clicking at that link works, but almost every time a new session is created.
What do you suggest me to do, to solve this?
Thank you very much.
Code: Select all
<?php
session_start();
if (!isset($_SESSION['test'])) {
echo "First activation: setting session variable";
$_SESSION['test'] = 1;
} else {
echo "SESSIONS ARE WORKING! activation: ", (++$_SESSION['test']);
?>
<br><a href="http://localhost:8081/testesession.php">Again</a>
<?php
}
echo "<br>" . session_id();
?>
Re: Loosing Session when clicking a link (a href)...
Posted: Sun Jun 01, 2008 4:36 pm
by califdon
You do realize that every script that employs session variables must have its own session_start(); statement, right?
Do all your linked scripts have it?
Re: Loosing Session when clicking a link (a href)...
Posted: Sun Jun 01, 2008 4:42 pm
by razer.anthom
Hi, thank you for your response...
Yes, all my scripts have session_start(), PHP.INI also have the 'session.cookie_domain' setted to blank (I saw in some sites that this is needed to work in LOCALHOST).
For example, that script I wrote here is linked to itself. It has session_start() at the top.
I don't know what is happening :S
Thank you very much.
Re: Loosing Session when clicking a link (a href)...
Posted: Sun Jun 01, 2008 5:47 pm
by Chris Corbyn
Do you have cookies disabled in your browser?
Re: Loosing Session when clicking a link (a href)...
Posted: Sun Jun 01, 2008 6:19 pm
by razer.anthom
Nope.. All allowed... I tested with IExplorer too, same behavior.
One more information, I tested in my real site, with domain etc et al, running linux, all configured well, and I get the same behavior. Maybe one of you can try that script in your servers... I think my script is wrong, but, I don't know where...
This is the 'session' configuration, get from
phpinfo() in my
localhost
Code: Select all
session
Session Support enabled
Registered save handlers files user sqlite
Registered serializer handlers php php_binary wddx
Directive Local Value Master Value
session.auto_start Off Off
session.bug_compat_42 Off Off
session.bug_compat_warn On On
session.cache_expire 180 180
session.cache_limiter nocache nocache
session.cookie_domain no value no value
session.cookie_httponly Off Off
session.cookie_lifetime 0 0
session.cookie_path / /
session.cookie_secure Off Off
session.entropy_file no value no value
session.entropy_length 0 0
session.gc_divisor 1000 1000
session.gc_maxlifetime 1440 1440
session.gc_probability 1 1
session.hash_bits_per_character 5 5
session.hash_function 0 0
session.name testao PHPSESSID
session.referer_check no value no value
session.save_handler files files
session.save_path c:/wamp/tmp c:/wamp/tmp
session.serialize_handler php php
session.use_cookies On On
session.use_only_cookies Off Off
session.use_trans_sid 0 0
Re: Loosing Session when clicking a link (a href)...
Posted: Sun Jun 01, 2008 11:07 pm
by razer.anthom
Hi all...
I made two more tests:
1) Installing a new WAMP Server: Same behavior;
2) Installing PHP+Apache in separate: Same behavior.
Why my "A HREF" are not keeping my sessions??????
Tnx

Re: Loosing Session when clicking a link (a href)...
Posted: Tue Jun 03, 2008 10:11 pm
by razer.anthom
NOthing new about this???

Re: Loosing Session when clicking a link (a href)...
Posted: Thu Jun 05, 2008 9:28 pm
by razer.anthom
Hi friends...
I have a new behavior... I noted that session is not lost.. But I need to wait 5 seconds (I counted) untill click a link. Otherwise, php creates another session....
Do you know why this is happening?
Thank you in advance...
Re: Loosing Session when clicking a link (a href)...
Posted: Fri Jun 06, 2008 1:08 am
by RobertGonzalez
Wow, that is odd behavior. I would say ditch the crappy WAMP setup and load each component manually. Then try again.
By default PHP sessions work with not intervention needed by you, cookies or not.
And for the record, what leads you to believe sessions are not working?
Re: Loosing Session when clicking a link (a href)...
Posted: Fri Jun 06, 2008 9:35 am
by razer.anthom
Thank you for your response...
Well, for now, sessions are working, but, it takes 5 seconds to wait before clicking a link... If I click a link before
5 seconds, new session is created ....
What can cause this behavior????
Thank you in advance.
Re: Loosing Session when clicking a link (a href)...
Posted: Fri Jun 06, 2008 10:50 am
by RobertGonzalez
I have never heard of that before so unfortunately I cannot help in this matter. Maybe someone else with more experience than me can take a stab at it.