473,322 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

new session always created on session_start()

3
Hi everybody,

I am moving a php site to new hosting, and what was working fine on the old hosting is now broken on new hosting. The problem is that session_start is always creating a new session, even though one exists. I can see that the cookie is created just fine locally on login, and the matching session file is created on the server. But once I go to a new page, my checklogin() calls session_start which returns a new empty session, and I am automatically logged out.

Here is how I create the session during login:
[PHP]if ($rs->RecordCount() == 1) { // Found a partner
session_start();
$_SESSION['real-usr'] = $usr;
}[/PHP]

Here is how I check that the user is logged in:

[PHP]function checkLogin() {
session_start();
if (empty($_SESSION['real-usr'])) {
echo "Session expired. Please login";
include("login.php");
die();
}
}[/PHP]

Note that it isn't shared hosting, so there shouldn't be a problem with other processes deleting the temporary session files. (Plus I can see that the temp files are still there.)

I am using PHP 5.2.2. Here is an exerpt from phpinfo()

session
Session Support enabled
Registered save handlers files user
Registered serializer handlers php php_binary wddx

Directive Local Value Master Value
session.auto_start Off Off
session.bug_compat_42 On On
session.bug_compat_warn On On
session.cache_expire 180 180
session.cache_limiter nocache nocache
session.cookie_domain .semoptimizer.com .semoptimizer.com
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 PHPSESSID PHPSESSID
session.referer_check no value no value
session.save_handler files files
session.save_path C:\Temp C:\Temp
session.serialize_handler php php
session.use_cookies On On
session.use_only_cookies Off Off
session.use_trans_sid 0 0

If anybody can give me a hand, it would be much appreciated. I have been doing google searches all day and investigating different options, but haven't figured anything out.

Thanks,

jessica
Jun 4 '07 #1
6 3986
epots9
1,351 Expert 1GB
i'm not 100% sure but maybe the problem is that your calling session_start() inside your functions.

session_start() should be the first line (after the <? tag), before any other code is used, and should only be called once per php file.

does that work?
Jun 5 '07 #2
smudge
3
i'm not 100% sure but maybe the problem is that your calling session_start() inside your functions.

session_start() should be the first line (after the <? tag), before any other code is used, and should only be called once per php file.

does that work?
Nope, that didn't fix it. It's still doing the same thing.
Jun 5 '07 #3
Motoma
3,237 Expert 2GB
This may be an issue with the session cookie options. Try creating a cookie yourself and see if you get the same Host, Path, and Domain information in that cookie as you do in your Session cookie.
Jun 5 '07 #4
smudge
3
This may be an issue with the session cookie options. Try creating a cookie yourself and see if you get the same Host, Path, and Domain information in that cookie as you do in your Session cookie.
Thanks! That did the trick. The domain was missing a www and the path was / instead of \.
Jun 5 '07 #5
Motoma
3,237 Expert 2GB
Thanks! That did the trick. The domain was missing a www and the path was / instead of \.
Glad you got everything working, and thanks for posting the solution so others may learn too.
Come back to the site any time you have a problem.
Jun 5 '07 #6
jx2
228 100+
try that :
[PHP]if(!(session_id()))session_start();[/PHP]

why do you use it many times?
i woud use it once at first line
let me know if it works...
jx2
Jun 6 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Wynter | last post by:
I've been smacking into one brick wall after the next in converting some of my code from ASP Classic to ASP.NET. This one is a real bugger. I use Session Variables to help with User Security. If they...
1
by: soudifathy | last post by:
whene i use localhost/... and navigate through web site the session id not changed but whene i use computername/.. (ie. computerName/home.aspx) sessionID is created each page and the data is lost...
19
by: Andrew J. Marshall | last post by:
I want to create a class that must receive a parameter when instantiated. In other words, I do not want it to have a "Public Sub New()". 1) Does VB.NET create a default public constructor if I do...
16
by: Jonathan Wood | last post by:
Greetings, I was wondering if anyone here has a good understaning of the Session object. I know there are options like the Session.Abandon method and the regenerateExpiredSessionId setting,...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.