Ok, This login page is supposed to take variable from a form on another page and login the user, instead it redirects back to the main page without loging in.... Any ideas?PHP Code:<?php
session_start();
// Connects to the database
$test = mysql_connect("localhost", "root", "mypass") or die(mysql_error());
mysql_select_db("php", $test) or die(mysql_error());
// Someone wants to lohhin
if (isset($_POST['login'])) {
//Looking for the pass/user in the database
$query = mysql_query("SELECT * FROM php WHERE user='" . $_POST['user'] . "' AND password='" . $_POST['pass'] . "'") or die(mysql_error());
print mysql_error();
if (mysql_num_rows($query) == 1) {
// If the user and pass a valid
$_SESSION['login'] = "true";
$_SESSION["user"] = $_POST["user"];
echo 'Welcome '.$_SESSION["user"].' you are logged in!';
} else {
// It its wrong
die("Wrong logininfo.");
}
}
// Someone want to logout
if (isset($_GET['action']) && $_GET['action'] == 'logout' && isset($_SESSION['login'])) {
unset($_SESSION['login']);
session_destroy();
header("Location: ../index.php");
}
// Someone is a member
if (isset($_GET['action']) && $_GET['action'] == 'member') {
echo "Welcome member";
}
if (isset($_SESSION['login']) && $_SESSION['login'] == "true") {
// This is shoewd if you are logged in!
header("Location: ../index.php");
// This will show if you aint logged in.
} else {
?>
<html>
<body bgcolor="#666666" text="#ffffff">
<table width="200" border="0" cellspacing="5" cellpadding="0" align="center" valign="middle">
<tr>
<td style="border: 1 solid #333333;" bgcolor="#777777">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#333333"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">[b]<font color="#ffffff">»</font><font color="#ffffff">Log in
</font>[/b]</font></td>
</tr>
<tr>
<td bgcolor="silver"><font size="1" face="Verdana, Arial, Helvetica, sans-serif" color="#ffffff">
<center>
<form method="post" action="<?= $_SERVER['PHP_SELF'] ?>">
[b]Username:[/b]
<input type="text" name="user">
[b]Password:[/b]
<input type="password" name="pass">
<input type="submit" name="login" value="Login">
</form>
</center>
</font>
</td>
</tr>
</table>
</td>
</tr>
</table>
<?
}
?>




Reply With Quote