Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

location header in code

Posted on 2013-12-22
3
Medium Priority
?
402 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 84

Accepted Solution

by:
Dave Baldwin earned 2000 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 84

Expert Comment

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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …
Suggested Courses

926 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