Jump to content

[Resolvido] Ajuda UCP


xcape
 Share

Recommended Posts

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:

<?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 

 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.

Edited by apocsantos
geshi
Link to comment
Share on other sites

os header, que escreveste assim: echo header("Location: home.php"); não se chamam por echo, é apenas: header("Location: home.php");

os header só devem ser chamados no inicio do código, portanto estás a programar mal, aconselho-te a usares assim:

?>
<META http-equiv="refresh" content="0;URL=home.php">
<?php

Em que o 0 antes de ;URL é o tempo que de pausa antes de fazer o redirect.

Isso resolve o teu problema 😉

PS: Não sei quem escreveu esse código que estás a usar, mas digo-te que essa pessoa devia primeiro aprender a programar e só depois fazer algo, isto:

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

É das coisas mais ridículas que já vi no assunto da programação!

muda esse código por:

if(isset($_POST['submit'])){
   $submit = $_POST['submit'];
   $username = $_POST['username'];
   $password = $_POST['password'];

e retira essa linha que diz:

error_reporting(0); //without this we will always get some stupid notice that variable isn't defined....

Que está a ocultar os erros que podem acontecer, dificultando-te a encontrar-los...

developer @ filipealves.net

filipealvesbcl [a] gmail.com

github.com/filipealvesbcl

Link to comment
Share on other sites

os header só devem ser chamados no inicio do código, portanto estás a programar mal, aconselho-te a usares assim:

isso não é assim

a chamada da função header, que altera o header HTTP a ser enviado para o cliente, tem que ser realizada antes de ser enviado qualquer informação para o output.

não existe nenhuma regra que indica que essa chamada tenha de ser realizada dentre de X linha do início do script.

uma solução por HTML não faz sentido nenhum pois obriga ao processamento do HTML, algo que é feito após do tratamento do protocolo HTTP fazendo que o processo se torna mais lento do que necessário.

IRC : sim, é algo que ainda existe >> #p@p
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.