Solved

location header in code

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

830 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