php - Session variable not staying set -
warning: not duplicate, can't find problem.
i'm testing , building website on localhost. have following code on login page, sending user profile page if have user id cookie, , ip same cookies says should be.
if($_cookie["ipcookie"] == $_server['remote_addr']) { $cookieresult = mysqli_query($connection, 'select count(`id`) count users username="$_cookie["usercookie"]" , `active`="1"'); if($cookieresult == 0) { $loginquery = mysqli_query($connection, "select * users username=" .$_cookie['usercookie']); $row5 = mysqli_fetch_assoc($loginquery); $dbidlogin = $row5['id']; $_session['userid'] = $dbidlogin; header('location: /userprofile.php'); }
however, when go user profile using these cookies, $_session['userid']
null
. can't seem figure out why "sometimes" $_session
goes null
. can't seem find pattern in it. login 1 user, click links on profile page go different areas of website , go loginuser.php
(the file shown above), , works 1 user, doesn't another. seems random, confuses me. can't think of reason change inbetween users. i'll continue test this, , see if can find pattern, several hours put in already, appears random.
my problem not appear answered of these:
php session data lost between page loads wampserver 2.0 on localhost -i checked php.ini, has lines of code (though different, functioning tmp file). example code in selected answer testing $_session variable works charm. code, doesn't.
php session not saving session_save_path()
writable.
php session not being saved between pages php session data not being saved i'm on localhost, not server.
session_start();
on every page, excluding templates referenced in pages have session_start();
@ beginning (because if session_start();
in template comes error how session started).
update: may have pattern. users usernames including letters not have information saved. of these users have longer usernames, usernames words "dummy" , "eport" opposed "1" , "9." works 1 , 9, not dummy , eport. now, makes no sense, identified id's numbers, appear pattern.
update(the relevant code userprofile.php):
<?php $userid = $_session['userid']; var_dump($_session['userid']); //get. $totalquery = mysqli_query($connection, "select * users id='$userid'"); $arrayquery = mysqli_fetch_assoc($totalquery); $username = $arrayquery['username']; //firstname $firstname = $arrayquery['firstname']; echo 'welcome ' . $firstname; //lastname ?>
this bit of code nothing:
$cookieresult = mysqli_query($connection, 'select count(`id`) count users username="$_cookie["usercookie"]" , `active`="1"');
as $cookieresult loosely equal 0
(it false
) when query fails. guessing need read data out of result resource handle gets set $cookieresult
determine value count(id)
.
Comments
Post a Comment