Jump to content

[SOLVED] header help


Vitamin

Recommended Posts

<?php
$link = mysql_connect('localhost', 'root', 'root');
$selectdb = mysql_select_db ('chfa', $link);

$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);

if(isset($_POST['submitinfo'])) {
if($username=="" || $password=="")
{
die("Please do not leave the username / password field blank!");
}
$result = mysql_query("SELECT * FROM admin WHERE
username='$username' AND pass='$password'");
$number = mysql_num_rows($result);
if($number==0)
{
die("Your login details are not right. Please click the back button
and correct them.");
}
setcookie ("auth", "yea", time()+3600);
header ("location: main.php");
}

?>

 

Everything works up to the point of the header statement.  How can I get a redirect to a different page?

Link to comment
https://forums.phpfreaks.com/topic/154131-solved-header-help/
Share on other sites

Include the full URL in your header-location

 

<?php
...
header ("Location: http://www.site.com/main.php");
exit();
...
?>

 

And be sure not echoing anything before the header, including space or cariage return. And put a exit()/die() after the header because the page will be executed and the results may be returned to the browser. (not sure if the results is actually send to the browser but the page will be executed, including any SQL query, ....)

 

http://www.php.net/manual/en/function.header.php

Link to comment
https://forums.phpfreaks.com/topic/154131-solved-header-help/#findComment-810221
Share on other sites

Does your script report any error ? What does it do ? nothing ?

 

Did you set your error reporting like that :

 

<?php
ini_set ("display_errors", "1");
error_reporting(E_ALL);
?>

 

Use telnet yoursite.com 80 to see the exact output of your script OR use some website like http://web-sniffer.net/ Can show you the http header with http content your script output.

Link to comment
https://forums.phpfreaks.com/topic/154131-solved-header-help/#findComment-810231
Share on other sites

I get these errors when I do that

Notice: Undefined index: username in C:\server\www\myserver.dev\public_html\test\do_login.php on line 7

 

Notice: Undefined index: password in C:\server\www\myserver.dev\public_html\test\do_login.php on line 8

 

which is the setting or username and password.

 

but if I echo where the header line is insted of the header the echo works.

Link to comment
https://forums.phpfreaks.com/topic/154131-solved-header-help/#findComment-810239
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

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.