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..
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..