Hello everyone!
I have a login script but i want to made an "if" statement where the user is logged in to be redirected to admin.php and where the user is not logged in to be redirected to login.php.
What i have now is the login script that encrypt the password and the username to md5 and after that to sha1 (i think!):
login.php
<?php
session_start();
if(isset($_COOKIE['admin']))
{
include 'config.php';
$username = $_COOKIE['admin']['username'];
$password = $_COOKIE['admin']['password'];
$username = safeAddSlashes($username);
$password = safeAddSlashes($password);
$db = mysql_connect($dbHost,$dbUser,$dbPass);
mysql_select_db($dbname,$db);
$query = "SELECT user, pass FROM login WHERE user = '$username' AND pass = '$password'";
$result = mysql_query($query, $db);
if(mysql_num_rows($result))
{
$_SESSION['loggedin'] = 1;
header('Location: '.$domain.'admin.php');
exit();
}
}
?>
<?php include('includet/head.html')?>
<center><div class="faqeident">
<div class="identtitull"> Paneli Administrimit Për Agalliu.Com </div>
<div class="identifikimi">
<form method="post" name="cookie" action="process.php" style="float:right; margin-right:130px; margin-top:50px; font-family:Tahoma, Verdana, Arial; font-size:13px; color:#4F4F4F;">
<p><label for="username">Pseudonimi : <input type="text" name="username" id="username" /></label></p>
<p><label for="password">Fjalëkalimi : <input type="password" name="password" id="password" /></label></p>
<p><input type="checkbox" name="setcookie" value="setcookie" /> Ruaj Sesionin</p>
<p><td width="80" height="23"><input type="submit" name="submit" value="Identifikohu" class="buton" /></td>
<td width="80" height="23"><input type="reset" name="reset" value="Boshatis" class="buton" /></td></p>
</form>
</div>
<div class="identgabim">
<?php
if (isset($_GET['error']) AND !empty($_GET['error']))
{
echo '<img src="imazhet/ndal.gif" alt="Operacion i gabuar" width="50" height="50" align="left"> Keni kerkuar te aksesoni një faqe të mbrojtur <br /> ose të dhënat e vendosura nuk janë të sakta.';
}
?>
</div>
</div></center>
config.php
<?php
$dbHost = 'localhost';
$dbUser = 'user';
$dbPass = 'pass';
$dbname = 'dbname';
$domain = 'http://localhost/joni/admini/';
function safeAddSlashes($string) {
if (get_magic_quotes_gpc()) {
return $string;
} else {
return addslashes($string);
}
}
function Encrypt($string)
{
return sha1(md5($string));
}
?>
and to prevent access of un-logged users i use:
session_start();
if(!isset($_SESSION['loggedin'])) {
header('Location: '.$domain.'index.php?error=1');
exit();
}
Now, i want to create that statement to index.php and when the user is logged in to be redirected to the main admin page named admin.php, or, if the user is not logged in to be redirected to login page named login.php
Thank you in advance!