PDA

View Full Version : Need help with cookies



Drugs
09-08-2006, 10:35 PM
Ok so for the login to admin panel on my site i put it to create a cookie with the value '1' so you put on the passworded pages that it required a cookie with the value '1' like this;

if($_COOKIE['in'] == "1"){}
else{
die("You are not authrised to view this page.");
}

Now i tried to make a moderator login so its basically the same as the admin login but it sets the cookie to "2" and i put this code on the pages that moderators need;

if($_COOKIE['in'] == "1" && "2"){}
else{
die("You are not authrised to view this page.");
}

Thats so admin and moderators can access the page, it works fine but when you login through the moderator login, it goes to a moderator page when the login was successful but says Not logged in so it isnt setting the cookie correctly, this is what i use for the admin login;



<?php
if ($_SERVER['REQUEST_METHOD']=="POST"){

// Get UserNames and Passwords.
$Logi = file("users/users.txt");
// Work out how many there are
$size = sizeof($Logi);
// Break appart passwords and usernames
foreach($Logi as $Key => $Val)
{ $Data[$Key] = explode("||", $Val); }
// run threw list and see if any match
for($K = 0; $K<$size; $K++)
{
$user = $Data[$K][0];
$pass = $Data[$K][1];
// If match set cookie and redirect.
if ($user == trim(addslashes($_POST["user"])) && $pass == trim(addslashes($_POST["pass"])) )
{
setcookie("in", 1, time()+3600);
// Start hidden page
header("Location: adminindex.php");
}
}
echo "Login Failed.";

// If you didnt log in show login form
} else { ?>
<div style="width:250px">
<div><strong><font face='verdana'><font size=1><b>Admin Login</b></strong></div><br><br>
<div><form name="Login" method="post" action="<?=$_SERVER['PHP_SELF'];?>">
Username;<br>
<input name="user" type="text" >
<br><br>
Password;<br>
<input name="pass" type="password" >
<br><br>
<input type="submit" name="Submit" value="Submit">
</form>
</div></div>
<?php

// Copyright PixelResources 2006 - 2007

?>

<?php
}
?>


And this is what i use for mod login;



<?php
if ($_SERVER['REQUEST_METHOD']=="POST"){

// Get UserNames and Passwords.
$Logi = file("users/mods.txt");
// Work out how many there are
$size = sizeof($Logi);
// Break appart passwords and usernames
foreach($Logi as $Key => $Val)
{ $Data[$Key] = explode("||", $Val); }
// run threw list and see if any match
for($K = 0; $K<$size; $K++)
{
$user = $Data[$K][0];
$pass = $Data[$K][1];
// If match set cookie and redirect.
if ($user == trim(addslashes($_POST["user"])) && $pass == trim(addslashes($_POST["pass"])) )
{
setcookie("in", 2, time()+3600);
// Start hidden page
header("Location: modindex.php");
}
}
echo "Login Failed.";

// If you didnt log in show login form
} else { ?>
<div style="width:250px">
<div><strong><font face='verdana'><font size=1><b>Admin Login</b></strong></div><br><br>
<div><form name="Login" method="post" action="<?=$_SERVER['PHP_SELF'];?>">
Username;<br>
<input name="user" type="text" >
<br><br>
Password;<br>
<input name="pass" type="password" >
<br><br>
<input type="submit" name="Submit" value="Submit">
</form>
</div></div>
<?php

// Copyright PixelResources 2006 - 2007

?>

<?php
}
?>


But for some reason its not working..

Luckyrare
10-08-2006, 06:00 AM
Its much easier when you just use mysql. Also just using cookies is very unsafe, I could get into it in about 5 seconds you need to check the username againts the password aswell....

www.php.net/mysql

Good luck,
Danny

Tomm
10-08-2006, 06:22 AM
Yeah lol, all you need to do is create the cookie in and set it to 1 and I am in lol. Also the modcp wont work in you used and and not or..

Want to hide these adverts? Register an account for free!