Solved

location header in code

Posted on 2013-12-22
3
388 Views
Last Modified: 2013-12-22
Hi,

What is suppose to do:

f($password1 != $password2)
{      
    header("Location: registration.html");
}

i don't know what happens, is this supposed to exit the rest of the code?, because i run it and still writing in my table on the database. Any idea?

<?php
//retrieve our data from POST
$username = $_POST['username'];
$password1 = $_POST['password1'];
$password2 = $_POST['password2'];
$email = $_POST['email'];
 
if($password1 != $password2)
{	
    header("Location: registration.html");
}
if(strlen($username) > 30)
{
    header("Location: registration.html");
}
	
$hash = hash('sha256', $password1);
 
function createSalt()
{
    $text = md5(uniqid(rand(), true));
    return substr($text, 0, 3);
}
 
$salt = createSalt();
$password = hash('sha256', $salt . $hash);

$conn = mysql_connect('localhost', 'root', 'root');
mysql_select_db('login', $conn);
 
//sanitize username
$username = mysql_real_escape_string($username);
 
$query = "INSERT INTO member ( username, password, email, salt )
        VALUES ( '$username', '$password', '$email', '$salt' );";
mysql_query($query);
 
mysql_close();
 
header('Location: index.html');
?>

Open in new window

0
Comment
Question by:joyacv2
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 39735319
It's only supposed 'redirect' if $password1 and $password2 are not exactly the same.

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

The example code on that page says you should put an 'exit;' statement after the header() line to make sure that nothing else gets executed.
0
 
LVL 1

Author Closing Comment

by:joyacv2
ID: 39735350
perfect, the exit statement solves the problem!!!!
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 39735383
Good.  Make sure you put it after each header() statement.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now