ok, i'm new to sessions here. I have made a very basic login script that uses a normal session and the session is parsed into the url i.e
whatever.php?".session_name()."=".session_id()."
now that works great, but I really don't like the layout and I want my users to be able to "stay logged in" so i wanted to use a database table session's to do this.
insert a time to timeout teh session at which point any page is run and anything before that time in the database is deleted and those uers's session's destroyed.
i have a script that does the insert and selects the info back out of the database that I came up with that goes like this:
function startSession($username, $pass) {
global $cookie, $mysql_access;
$newpass = md5($pass);
$_SESSION['session']['username'] = $username;
$_SESSION['session']['password'] = $newpass;
$_SESSION['session']['loggedIn'] = true;
if($cookie = "yes") {
$sessionid = session_id();
$query = mysql_query("INSERT INTO session SET sessiond='$sessionid',
username = '".$_SESSION['session']['username']."',
password = '".$_SESSION['session']['password']."',
cookie = '$cookie'")
or DIE("Error adding session to db. If MySQL had an error it is <br /> ". mysql_error());
} else {
}
}
function getSession() {
global $mysql_access;
$query = mysql_query("SELECT * FROM session WHERE username='".$_SESSION['session']['username']."'
AND password='$getpass'")
or DIE("Cannot get session from database. If MySQL had an error
it is <br /> ". mysql_error());
}
every page does start with session_start(); and my script is working.. however, staying logged i do not think is. Would I have to set a cookie as well as use the database?
am I missing something here?
i'm actually thinking this now... when the info get's pulled from the database.... shouldn't it be more like this
$time = "";//some value
$query = mysql_query("SELECT * FROM session WHERE timeout > '$time' ");
no that wouldnt' work either... what I dont' understand is this:
in order to pull a certian person's session back from the database, you have to have a variable to math it to, to pull the correct one.
I'm pretty sure that's where cookie's come in. Now setcookie(); has it's problems, so if i do need to use cookie's i will use Javascript.
but then I read when I researched this idea on this board that you should not use cookie's and session's... now i'm lost 🙁
any help is greatly appreciated.