I am trying to make a login code with PHP, this is what I got on the login page:
<?php
require("../_cookie.php");
$name = $_POST["name"];
$password = $_POST['password'];
//Connect;
$con = mysql_connect("localhost:Database","savagew_savagew","...");
if (!$con){
die('Could not connect: ' . mysql_error());
}
//Select the db;
mysql_select_db("savagew_Database", $con);
$result = mysql_query("SELECT * FROM Users WHERE Name = '$name'");
//Store in arrays;
while($row = mysql_fetch_array($result)){
if(---($password) == $row['Password']){
$loginSuccess = true;
}else{
$fail[] = "Error 1: Wrong Password";
};
};
if($loginSuccess){
session_name($ip);
session_start();
$_SESSION['login'] = ''.$name.'';
// echo $_SESSION['login'];
};
$i = 0;
$failMessage = "Errors:";
while(true){
if($fail[$i] == null){
break;
};
$failMessage .= "+".$fail[$i];
$i ++;
};
if($failMessage == "Errors:"){
//header('Location: '.$_SERVER["HTTP_REFERER"]);
}else{
passToJS("from", $_SERVER["HTTP_REFERER"]);
passToJS("fail", $failMessage);
};
var_dump($_SESSION); // Dumps "array(1) { ["login"]=> string(10) "SavageWolf" } " in my testing;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<?php require("../_head.php")?>
<title>[LOGIN]</title>
</head>
<body>
<script language="JavaScript">
if(fail != "Errors:"){
fail = fail.split("+");
totalFail = ""
for(var i in fail){
totalFail += "\n" + fail[i];
};
alert(totalFail);
};
if(from == ""){
window.location = "http://www.wolfthatissavage.com/home.php";
}else{
window.location = from;
};
</script>
</body>
</html>
And on the pages:
<?php
session_name($ip);
session_start();
if(isset($_SESSION['login'])){
$userName = $_SESSION['login'];
$loggedIn = true;
//Connect;
$con = mysql_connect("localhost:Database","savagew_savagew","...");
if (!$con){
die('Could not connect: ' . mysql_error());
}
//Select the db;
mysql_select_db("savagew_Database", $con);
$result = mysql_query("SELECT * FROM Users WHERE Name = '$userName'");
//Store in arrays;
while($row = mysql_fetch_array($result)){
//Boring stuff
};
}else{
$loggedIn = false;
};
echo $_SESSION['login'];
?>
With another dump at the bottom of the page, returning “NULL” or "array(0) { } "
Help?
Loading