Jump to content

Session problems


tiptip

Recommended Posts

hello , im having some problem, and i did google alot and try different solution non have worked, ill try to give as much details as i can..

my code conatain some stuff like getting info from mysql DB , but i paste here only the part of code i have problem with.

also i wrote this simple session code in my page just to make easy check on if it works.

 

code:

 

<?php

session_start();

$_SESSION['test'] = "adam";

header('location: http://******.Index.php');

?>

 

now this code sit in a file called check.php and it called from an other php file contain form.

now when the code run like this , and i move to page index.php the "echo $_SESSION['test'];" return empty.

when i remove the header and put <a> tag link to index.php again "echo $_SESSION['test'];" return empty.

when i remove the header totally, the call this code, and then write the link "www.****/.index.php" in the browser url bar , then echo $_SESSION['test']; return "adam" like it should...

 

after looking on this problem on google, i try to add exit(0); after the header , that didnt work.

also try to add session_write_close(); before the header , this also didnt work...

 

any ideas???

thanks a head

Link to comment
https://forums.phpfreaks.com/topic/273276-session-problems/
Share on other sites

Your links and redirect statements are changing the www. vs no-www. in the URL and the session id cookie doesn't match all variations of your domain name.

 

A) You need to be consistent in using a www. or no-www. on your domain name,

 

B) You need to redirect any request that doesn't have the www. on it to the same url with the www. on it (or visa-versa.)

 

C) You need to set the session cookie id domain setting so that it matches all variations of your domain name. See the 'domain' parameter at this link - http://us1.php.net/session_set_cookie_params

Link to comment
https://forums.phpfreaks.com/topic/273276-session-problems/#findComment-1406447
Share on other sites

well thanks alot.

after you showed me what is the problem, i was able to solve it in much easyer way , i just redirect path to the file in my server, and not call www ....

but i still was reading about session_set_cookie_params and i gonna play with it little just for the understanding...

 

thanks for your help...

Link to comment
https://forums.phpfreaks.com/topic/273276-session-problems/#findComment-1406453
Share on other sites

Archived

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

×
×
  • Create New...

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.