Boas noites,
É o seguinte eu estou a fazer um Painel de Jogador para um servidor de SAMP, o painel esta ligado há base de dados do servidor, e para dar login é preciso ter um registo no sv que depois ao dar login vai buscar a conta a base de dados só que quando vou a fazer login, ele não redirecciona para a próxima pagina, já tive a ver mais do que uma vez e não sei o que se passa.
Aqui esta o código:
Código (PHP):
Aguardo Resposta....
Cumprimentos.
É o seguinte eu estou a fazer um Painel de Jogador para um servidor de SAMP, o painel esta ligado há base de dados do servidor, e para dar login é preciso ter um registo no sv que depois ao dar login vai buscar a conta a base de dados só que quando vou a fazer login, ele não redirecciona para a próxima pagina, já tive a ver mais do que uma vez e não sei o que se passa.
Aqui esta o código:
Código (PHP):
<?php
ob_start();
$connect = mysql_connect("localhost", "xogqpdeh_ucp", "lostucpvillage123") or die("Can't Connect To the Server"); //connecting to mysql
mysql_select_db("xogqpdeh_ucp") or die ("Database Not Found"); // database name
function sanitize($string) // unction for sanitize from xss and mysql and csrf.
{
$string = strip_tags($string);
$string = mysql_real_escape_string($string);
return $string;
}
//include("config.php"); // including our config.php where is connecting to mysql...
session_start(); //starting session for profile.php (Dunno how to explain better) look little down
error_reporting(0); //without this we will always get some stupid notice that variable isn't defined....
$submit = $_POST['submit']; //variable for submit button, in this variable we save button that player press in <input type='submit' name="submit" value='Login' />....
$username = sanitize($_POST['username']); //variable for username, in this variable we save text that user type in <input type="text" name="username"....
$password = sanitize($_POST['password']); //variable for password, in this variable we save text that user type in <input type="password" name="password"....
if($submit) //if he press submit button
{
echo $username;
echo $password;
if($username && $password) //if he type both of username and password not just one of them
{
$query = mysql_query("SELECT Nome, Password FROM contas WHERE Nome = '$username'"); //selecting user name and password, change it to your field names, chage users to your table name, $username means username that he type...
if(mysql_num_rows($query) == 1) //if user exists
{
while($row = mysql_fetch_assoc($query)) //loop thought table that we select in mysql_query
{
$dbusername = $row['Nome']; //setting dbusername as variable from table, change 'username' to your field!
$dbpassword = $row['Password']; //setting dbpassword as variable from table, change 'password' to your field!
}
if($username == $dbusername && $password == $dbpassword) //if username is same as one from table and if password is the same as one from table...
{
echo "$dbusername ";
echo "$username ";
echo "$password ";
echo "$dbpassword";
$_SESSION['username'] = $dbusername; //setting session username to one from table, this is useful if you login, that restart your browser and than you go in url where is your profile.php... Anyway this is useful :D
echo header("Location: home.php"); //redirecting user to his profile page (profile.php)
}
else echo header("Location:login_attempt.php"); //else if user type wrong password he will get this...
}
else echo header("Location: login_attempt.php"); //if username doesn't exist in table user will get this
}
else echo header("Location: login_attempt.php"); //else if user doesn't type all fields he will get this...
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href="css/style.css" rel='stylesheet' type='text/css' />
<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
</head>
<body>
<div class="main">
<div class="login">
<div class="inset">
<form action='index.php' method='POST'>
<div>
<span><label>Nome da Conta</label></span>
<span><input type="text" name="username" class="textbox" id="active" value='<?php echo $username?>'/></span>
</div>
<div>
<span><label>Password</label></span>
<span><input type="password" class="password" name="password"/></span>
</div>
<div class="sign">
<div class="submit">
<input type='submit' name="submit" value='Login' onclick="myFunction()"/>
</div>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
ob_start();
$connect = mysql_connect("localhost", "xogqpdeh_ucp", "lostucpvillage123") or die("Can't Connect To the Server"); //connecting to mysql
mysql_select_db("xogqpdeh_ucp") or die ("Database Not Found"); // database name
function sanitize($string) // unction for sanitize from xss and mysql and csrf.
{
$string = strip_tags($string);
$string = mysql_real_escape_string($string);
return $string;
}
//include("config.php"); // including our config.php where is connecting to mysql...
session_start(); //starting session for profile.php (Dunno how to explain better) look little down
error_reporting(0); //without this we will always get some stupid notice that variable isn't defined....
$submit = $_POST['submit']; //variable for submit button, in this variable we save button that player press in <input type='submit' name="submit" value='Login' />....
$username = sanitize($_POST['username']); //variable for username, in this variable we save text that user type in <input type="text" name="username"....
$password = sanitize($_POST['password']); //variable for password, in this variable we save text that user type in <input type="password" name="password"....
if($submit) //if he press submit button
{
echo $username;
echo $password;
if($username && $password) //if he type both of username and password not just one of them
{
$query = mysql_query("SELECT Nome, Password FROM contas WHERE Nome = '$username'"); //selecting user name and password, change it to your field names, chage users to your table name, $username means username that he type...
if(mysql_num_rows($query) == 1) //if user exists
{
while($row = mysql_fetch_assoc($query)) //loop thought table that we select in mysql_query
{
$dbusername = $row['Nome']; //setting dbusername as variable from table, change 'username' to your field!
$dbpassword = $row['Password']; //setting dbpassword as variable from table, change 'password' to your field!
}
if($username == $dbusername && $password == $dbpassword) //if username is same as one from table and if password is the same as one from table...
{
echo "$dbusername ";
echo "$username ";
echo "$password ";
echo "$dbpassword";
$_SESSION['username'] = $dbusername; //setting session username to one from table, this is useful if you login, that restart your browser and than you go in url where is your profile.php... Anyway this is useful :D
echo header("Location: home.php"); //redirecting user to his profile page (profile.php)
}
else echo header("Location:login_attempt.php"); //else if user type wrong password he will get this...
}
else echo header("Location: login_attempt.php"); //if username doesn't exist in table user will get this
}
else echo header("Location: login_attempt.php"); //else if user doesn't type all fields he will get this...
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href="css/style.css" rel='stylesheet' type='text/css' />
<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
</head>
<body>
<div class="main">
<div class="login">
<div class="inset">
<form action='index.php' method='POST'>
<div>
<span><label>Nome da Conta</label></span>
<span><input type="text" name="username" class="textbox" id="active" value='<?php echo $username?>'/></span>
</div>
<div>
<span><label>Password</label></span>
<span><input type="password" class="password" name="password"/></span>
</div>
<div class="sign">
<div class="submit">
<input type='submit' name="submit" value='Login' onclick="myFunction()"/>
</div>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
Aguardo Resposta....
Cumprimentos.