Avatar of joyacv2
joyacv2Flag for Puerto Rico

asked on 

location header in code

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

PHP

Avatar of undefined
Last Comment
Dave Baldwin
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of joyacv2
joyacv2
Flag of Puerto Rico image

ASKER

perfect, the exit statement solves the problem!!!!
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Good.  Make sure you put it after each header() statement.
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo