Solved

location header in code

Posted on 2013-12-22
3
390 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 83

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 83

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

867 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

21 Experts available now in Live!

Get 1:1 Help Now