Jump to content

Redirection Help


BluMess

Recommended Posts

Heya,

I'm new here ;)

Anyway, I've started up a website and I'm trying to implement a feature where you log in and you get sent to another page if it works properly. I've got the login code which works perfectly, but when I try to put the redirection code in [ header("Location:blahblah") ] it just gives me a blank page. this is the code:

 

<?php

// login2.php

include("connection.php");

 

// Start a session. Session is explained below.

session_start();

 

 

 

// Same checking stuff all over again.

if(isset($_POST['submit'])) {

if(empty($_POST['username']) || empty($_POST['password'])) {

echo "Sorry, you have to fill in all forms";

                exit;

}

// Create the variables again.

$username = $_POST['username'];

$password = $_POST['password'];

// Encrypt the password again with the md5 hash.

// This way the password is now the same as the password inside the database.

$password = md5($password);

 

// Store the SQL query inside a variable.

// ONLY the username you have filled in is retrieved from the database.

$query = "SELECT username,password

  FROM `users`

  WHERE username='$username'";

 

$result = mysql_query($query);

if(!$result) {

// Gives an error if the username given does not exist.

// or if something else is wrong.

echo "The query failed " . mysql_error();

} else {

// Now create an object from the data you've retrieved.

$row = mysql_fetch_object($result);

// You've now created an object containing the data.

// You can call data by using -> after $row.

// For example now the password is checked if they're equal.

if($row->password != $password) {

echo "The chat service is in a state of dis-repair. Well the login box is, to be honest. Darn it, I knew I shouldn't have pressed that big red button!";

                        exit;

}

 

// By storing data inside the $_SESSION superglobal,

// you stay logged in until you close your browser.

$_SESSION['username'] = $username;

$_SESSION['sid'] = session_id();

// Make it more secure by storing the user's IP address.

$_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];

 

                header("Location:http://www.google.com");

?>

     

}

}

 

Yeah. the part which causes the trouble as far as I know is the redirect part - header("Location:http://www.google.com");

Obviously I don't want it to go to google, but it's just an example.

I really hope you guys can help - I managed to get it working once, by rejiggling the php tags about but I lost that and now it doesn't work :(

 

Any suggestions?

 

Thanks,

Chris

Link to comment
https://forums.phpfreaks.com/topic/104905-redirection-help/
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.