Jump to content

problems with sessions


SFB

Recommended Posts

I have a working login script using sessions. It works on xampp (my program to test my php files). when i transfered it to the dcole server the login worked correctly but the session did not last from page to page. I could use the session variables i set on the page i set them on but when i went to the home page, i could no longer use them. here is most of my script.

<?phpsession_start();$userlogedin = false;$username = $_POST["username"];$password = $_POST["password"];require_once("userdata.php"); //include the file that contains the user records$size = count($users);for ($i = 0; $i < $size; $i++){  if (($users[$i]['username'] == $username) and ($users[$i]['password'] == $password))  {    $userlogedin = true;    $_SESSION['username'] = $users[$i]['username'];    $_SESSION['first'] = $users[$i]['first'];    $_SESSION['last'] = $users[$i]['last'];    $_SESSION['email'] = $users[$i]['email'];    $_SESSION['website'] = $users[$i]['website'];  }}if($userlogedin){ $first = $_SESSION['first']; print "you should be loged in $first ";}else{ print"the username and password do <u>not</u> match!";}?>

the login works because when i type in my password and username it gives me the message you should be loged in Charles but when i type in nothing or something random it gives me the username and password do not match! so it must be something with my sessions. I know i can use the ones i set on the page i set them on because it gave me my name in the message that said that i was loged in. but i cant use the session on my home page where i go something like

<?phpsession_start();$username = $_SESSION['username'];$first = $_SESSION['first'];$last = $_SESSION['last'];$email = $_SESSION['email'];$website = $_SESSION['website'];?><?php if(isset($_SESSION['username'])){ print" Welcome $first $last | <a class='welcome' href='/login/profile.php'><div class='welcome'>Profile</div></a> | <a href='/login/logout.php'><div class='welcome'>logout</div></a> ";}else{ print"Welcome <a href='/login/newuser.php'><div class='welcome'>Guest</div></a>| <a class='welcome' href='/login'><div class='welcome'>Login</div></a>";}?>

I want to figure out why this is happening only on the dcole server. the sessions work just fine for me on xampp.

Link to comment
Share on other sites

ok here is some more info. dcole.ath.cx uses sessions in his site so they should work for me. the sessions that i have in my script work on xampp. i temporarily use xampp as a server sometimes. it is like apache on windows. i am still working on setting up apache and php and those things as a service on my own. but anyways i am thinking there must be a mistake or something in my code. strange things always happen to me...

Link to comment
Share on other sites

ok here is the real problem. session.cookie_domain is set to dcole.ath.cx I dont have my own php.ini anymore so could i somehow chage this with php?i think its like ini_set() but i'm not sure how to do this.

Link to comment
Share on other sites

well that didnt work. I found that the phpsessid cookie is not being set. I do not know what is causing this. sessions work for dcole but they are not working for me. its the same server, i must be doing something wrong.

Link to comment
Share on other sites

Cookies will only go to the domain that they are set to. If a cookie is set to dcole.ath.cx, it will only go to dcole.ath.cx. You can probably set the cookie to .ath.cx and have it work for all subdomains.

Link to comment
Share on other sites

i told dcole to just leave that blank and it would work for all domains. he said that that probably wasnt the reason my sessions are not working. i tryied the folowing code but it didnt work.

<?phpini_set ("session.cookie_domain", "snowforts.ath.cx");?>

edit: my changes did not save for some reason. i have to go and fix themi will try this again a bit laterEdit#2: the problem with the dcole server has been fixed! my sessions work again!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...