SA-MP Forums Archive
PHP wont header ! redirect. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: PHP wont header ! redirect. (/showthread.php?tid=651256)



PHP wont header ! redirect. - Zeus666 - 16.03.2018

PHP код:
<?php
 
require('config.php');
 
session_start();
 
// If form submitted, insert values into the database.
 
if (isset($_POST['password'])){
 
$username $_POST['username'];
 
$password $_POST['password'];
 
$username stripslashes($username);
 
$username mysql_real_escape_string($username);
 
$password stripslashes($password);
 
$password mysql_real_escape_string($password);
 
//Checking is user existing in the database or not
 
$query "SELECT * FROM `users` WHERE username='$username' and password='".sha1($password)."'";
 
$result mysql_query($query) or die(mysql_error());
 
$rows mysql_num_rows($result);
 if(
$rows==1){
 
$_SESSION['username'] = $username;
 
header("Location: profile.php"); // Redirect user to index.php
 
}else{
 echo 
"random text";
 }
 }else{
 }
?>
It just refreshes the login page even if i write correct username and password

PHP код:
form action="" method="post" name="login">
<
input type="text" name="username" placeholder="Username" required />
<
input type="password" name="password" placeholder="Password" required />
<
input type="image" src="https://i.imgur.com/uVoJ8Kl.pngg" />
</
form



Re: PHP wont header ! redirect. - Zeus666 - 16.03.2018

someone help/


Re: PHP wont header ! redirect. - Eoussama - 17.03.2018

I don't know about php that much, but this part kind of bugging me:
PHP код:
if($rows==1){ 
 
$_SESSION['username'] = $username
 
header("Location: profile.php"); // Redirect user to index.php 
 
}else{ 
 echo 
"random text"
 } 
 }else{ 
 } 
An if statement can only have one else.


Re: PHP wont header ! redirect. - jasperschellekens - 17.03.2018

Quote:
Originally Posted by Eoussama
Посмотреть сообщение
I don't know about php that much, but this part kind of bugging me:
PHP код:
if($rows==1){ 
 
$_SESSION['username'] = $username
 
header("Location: profile.php"); // Redirect user to index.php 
 
}else{ 
 echo 
"random text"
 } 
 }else{ 
 } 
An if statement can only have one else.
No, Nothing wrong he isnt using it twice at all. It is the else from if isset.


Add obstart(); on top and exit() after the header
Also Why are you copying vars from the post method? ThAts not even necessary.
And i Dont see an action at your form. It must refer to the page that obtains the code u are using to Check for the username and pw


Re: PHP wont header ! redirect. - BroZeus - 17.03.2018

header redirect method doesn't work if something has already been sent to the output stream, make sure there is no echo statement or HTML code above the header() line, also make sure that there is no faulty code above header() line which can potentially cause an error or warning message to be echoed and use exit() function after using header() function to avoid extra processing.


Re: PHP wont header ! redirect. - Zeus666 - 17.03.2018

I did all of them, still doesn't work.

<?php is the first code of my script.

Added the

PHP код:
<form action="profile.php" method="post" name="login">
<
input type="text" name="username" placeholder="Username" required />
<
input type="password" name="password" placeholder="Password" required />
<
input type="submit" src="https://i.imgur.com/uVoJ8Kl.png" />
</
form
But now profile.php it shows blank. If I remove profile.php from the action it shows fine (if i enter manually, my problem is that login buton won't send me to profile.php)


Re: PHP wont header ! redirect. - Zeus666 - 17.03.2018

up up


Re: PHP wont header ! redirect. - jasperschellekens - 17.03.2018

Your action shouldnt be profile.php. this is where you get redirected after login. Save this as login.php
Код:
<?php*

*require('config.php');*
*session_start();*
*//*If*form*submitted,*insert*values*into*the*database.*
*if*(isset($_POST['password'])){*
*$username*=*$_POST['username'];*
*$password*=*$_POST['password'];*
*$username*=*stripslashes($username);*
*$username*=*mysql_real_escape_string($username);*
*$password*=*stripslashes($password);*
*$password*=*mysql_real_escape_string($password);*
*//Checking*is*user*existing*in*the*database*or*not*
*$query*=*"SELECT***FROM*`users`*WHERE*username='$username'*and*password='".sha1($password)."'";*
*$result*=*mysql_query($query)*or*die(mysql_error());*
*$rows*=*mysql_num_rows($result);*
*if($rows==1){*
*$_SESSION['username']*=*$username;*
*header("Location:*profile.php");*//*Redirect*user*to*index.php*
*}else{*
*echo*"random*text";*
*}*
*}else{*
 echo 'form*action="login.php"*method="post"*name="login">*
<input*type="text"*name="username"*placeholder="Username"*required*/>*
<input*type="password"*name="password"*placeholder="Password"*required*/>*
<input*type="image"*src="https://i.imgur.com/uVoJ8Kl.pngg"*/>*
</form>**';
*}*
?>
Also stop bumping after short amount of time. There is a 24 hours bump rule

Edit : lmao my tablet replaced all spaces with stars weird


Re: PHP wont header ! redirect. - Zeus666 - 17.03.2018

Still doesnt work


Re: PHP wont header ! redirect. - jasperschellekens - 17.03.2018

Quote:
Originally Posted by Zeus666
Посмотреть сообщение
Still doesnt work
What does not work exactly? please be more specific. By the way are u using error_reporting(E_ALL); ?