Friday, January 13, 2012

Login Script working local but not on live environment


I seem to have a problem with a login script, it works on a local php dev box, but not on my live environment, i'm assuming i'm missing something can anyone advise further?




<?php
$user = $_POST["swtorun"];
$pass = $_POST["swtorpw"];

// Generate hash
$enc_pwd = hash('sha256', $pass);

// Connect to DataBase
include('../../settings.php');

$conn = mysql_connect($host,$username,$password);
$db = mysql_select_db($database, $conn);

// mySql Query users
$sql = "SELECT * FROM `users` WHERE username='$user' and password='$enc_pwd'";
$result = mysql_query($sql, $conn);

$count = mysql_num_rows($result); // number of results (should be 1)

if($count==1){
// initiate session
session_start();
$_SESSION['logged'] = "1";
echo "you are now logged in, return to the <a href=\"../../index.php\">index</a>";
} else {
echo "Wrong Username or Password";
}
?>

1 comment:

  1. Add session_start(); to the topmost part of your PHP code.

    ReplyDelete