Hello,
I have been looking at tutorials and pages on the net regarding cookies and sessions. Originally I thought my script was using both but then noticed it doesnt. I wanted to know if there is anything wrong with this code as my new server doesnt seem to like my log in script and wont allow access to the members pages.
This is my log in code
$check = fetch("SELECT username,password,verify FROM members WHERE username = '$login_username' AND password = '$encrypted_password' AND game = '$game' ");
if ($check[username])
{
if($check[verify]==1)
{
setcookie("username_$game",$check[username],time()+2678400);
setcookie("password_$game",$check[password],time()+2678400);
header("Location: main.php?game=$game");
}
elseif($check[verify]==0)
{
header("Location: login.php?game=$game
}
}
else
{
header("Location: login.php?game=$game.");
}
Does anyone know why this is? Also ... are there ways to make this code more secure by using sessions? Would I add a session and then use the cookie info in the session id? Sessions seem to confuse me.
The code used to call the cookies and check the users permission is located into an include file which all pages requiring member access has.
$userCookie = "username_$game";
$passCookie = "password_$game";
$getInfo = fetch("SELECT * FROM members WHERE username = '$HTTP_COOKIE_VARS[$userCookie]' AND password = '$HTTP_COOKIE_VARS[$passCookie]' AND game = '$game'");
$getInfo2 = fetch("SELECT * FROM members_profiles WHERE username = '$getInfo[username]' AND game = '$game'");
$username = $getInfo[username];
Then each page checks the rank level of the user and identifies them by their username and the information pulled by the $getInfo.
Is the very secure and is there a better way to code this? Are there any obvious faults or flaws with the code that may prevent the new server from allowing this code to work?
Many Thanks
Justin