Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 182
  • Last Modified:

Strange Session Cookie Problem

I'm using sessions with session_start() and cookies, and everything has been working fine.

Recently, when I first start a session it tries to put the Session ID in my links.  If I immediately reload the page, it correctly uses cookies.  

Am I doing something wrong, or is this a server issue?  I'm not using any strange code.

Thanks in advance!
0
danielmorrison
Asked:
danielmorrison
  • 3
  • 2
1 Solution
 
gruntarCommented:
This behaviour you just described is fine. When you access first page on your site you don't have cookie yet so PHP thinks cookies are not enabled and that is why you only see SESSION id first time and not after you reload or click on a link. Because second time browser returns cookie data with request and then PHP dont generate those links anymore.

cheers
0
 
danielmorrisonAuthor Commented:
gruntar,

Is there a way I can go straight to a cookie?  I've never seen this before.
0
 
gruntarCommented:
Yes, you can add line below into code before you start session.
<?php
ini_set('session.use_only_cookies', 1);
?>
But that means if user is blocking cookies he wont be able to log in.

cheers
0
 
danielmorrisonAuthor Commented:
apparently my hosting setup doesn't allow me to use ini_set().

Either way, why have I never run into this before?  gruntar, you say this is behavior is fine (which it is), but is it typical?
0
 
gruntarCommented:
Yes, this is typical behaviour. maybe you just didn't noticed before.

what if you try with .htaccess file if you cant use ini_set?

php_flag session.use_only_cookies "On"

Just a note. When you set cookies only that means users won't be able to log in if they have disabled them.

cheers

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now