Php Redirection is not working


#1

Hello,

I have my website hosted on 000webhost. Everything were working fine, however a today I notice that the redirect header no longer working while it still working on XAMMP server.


#2

Can you please paste your code here?


#3
<?php
session_start();
session_regenerate_id();
require_once('dbints.php');
require_once('genral_info.php');
$options = [
    'cost' => 11,
    'salt' => mcrypt_create_iv(52, MCRYPT_DEV_URANDOM),
];

$nameErr = $emailErr = $contactErr=$passErr="";
$name = $email = $contact="";
$err=0;


$username=htmlentities($_POST['u_name']);
$useremail=htmlentities($_POST['u_email']);
$usercontact=htmlentities($_POST['u_contact']);
$userpass=htmlentities($_POST['u_password']);




$stmt = $conn->prepare("SELECT * FROM user_reg WHERE user_email=?");
$stmt->bind_param("s", $useremail);
$stmt->execute();
$result = $stmt->get_result();
if($result->num_rows > 0) {
 
 $_SESSION['already']="You are already register";
 header('Location:../login.php');
 die();
}


$stmt->close();





if($err==0)
{
//User Name Validation
		if(empty($username))
		{
			 $_SESSION['nameErr'] = "Name is required";
			 $err=1;
		}
		else
		{
			$username=trim($username);
			$username=stripslashes($username);
			$username=htmlspecialchars($username);

				if (!preg_match("/^[a-zA-Z ]*$/",$username))
				{
		 			 $_SESSION['nameErr']="Only letters and white space allowed";
		 			 $err=1;
				}
		}

//User Email Validation

		if(empty($useremail))
		{
			 $_SESSION['emailErr'] = "Email is required";
			 $err=1;
		}
		else
		{
			$useremail=trim($useremail);
			$useremail=stripslashes($useremail);
			$useremail=htmlspecialchars($useremail);

				if (!filter_var($useremail, FILTER_VALIDATE_EMAIL))
				{
		 			 $_SESSION['emailErr'] ="Only letters and white space allowed";
		 			 $err=1;
				}
				
		}

//User Contact Number Validation

		if(empty($usercontact))
		{
			 $_SESSION['contErr'] = "Contact Number is required";
			 $err=1;
		}
		else
		{
			$usercontact=trim($usercontact);
			$usercontact=stripslashes($usercontact);
			$usercontact=htmlspecialchars($usercontact);

				if (!preg_match('/^\d+$/',$usercontact) )
				{
		 			 $_SESSION['contErr'] ="Contact numer is not valid";
		 			 $err=1;
				}
				$lengh = strlen($usercontact);
				if ($lengh!=10)
				{
		 			 $_SESSION['contErr'] ="Enter Valid Contact Number";
		 			 $err=1;
				}
		}

//User Password Validation

		if(empty($userpass))
		{
			 $_SESSION['passErr'] = "Password is required";
			 $err=1;
		}
		else
		{
			$userpass=trim($userpass);
			$userpass=stripslashes($userpass);
			$userpass=htmlspecialchars($userpass);
				if (strlen($userpass)<6)
				{
		 			 $_SESSION['passErr'] ="Please Enter Atleast 6 Charactor or Digit";
		 			 $err=1;

				}

		}

//redirect to director

				if($err==1)
				{
				$_SESSION['username']=$username;
				$_SESSION['useremail']=$useremail;
				$_SESSION['usercontact']=$usercontact;
					header("Location:../reg.php");
					die();
				}
}



$pword=password_hash('$userpass', PASSWORD_BCRYPT, $options);


//start information enter in data base
	if($err==0)
	{


		//Unset field value sessions;
		if (isset($_SESSION['username']) || isset($_SESSION['useremail']) || isset($_SESSION['usercontact'])|| isset($_SESSION['userpass'])){
		session_unset('username');
		session_unset('useremail');
		session_unset('usercontact');
		}
		// Unset error sessions
		if(isset($_SESSION['passErr']) || isset($_SESSION['contErr']) || isset($_SESSION['emailErr']) || isset($_SESSION['nameErr'] ) )
		{
		session_unset('passErr');
		session_unset('contErr');
		session_unset('emailErr');
		session_unset('nameErr');
		}
	}

//information related to IP;
    $c_code = $CountryCode;
    $country = $Country;
    $state = $State;
    $s_code = $StateCode;
    $city = $City;

//Information related to Device
	$browser = $browser ." ".$bversion;
 	$os = $os_platform ;
 	$regdate= date("d-m-Y");

// code for insert into database
$stmt = $conn->prepare("INSERT INTO user_reg (user_name, user_email, user_contact, user_password, reg_date, user_browser, user_os, user_countrycode, user_country, user_statecode, user_state, user_city) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("ssssssssssss", $username, $useremail, $usercontact, $pword, $regdate, $browser, $os, $c_code, $country,$s_code,$state,$city);
if($stmt->execute())
{
	$_SESSION['useremail']=$useremail;
	header('Location:../');
}
$stmt->close();






/*

$pword=password_hash("admin31december", PASSWORD_BCRYPT, $options);

$admin="insert into admin_ac(admin_user,admin_password) values ('$uname','$pword')";

if(mysqli_query($conn,$admin))
{
	echo "successfull inserted";
}
else{
	echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
*/
?>

#5

Try this

<?php
session_start();
ob_start();
session_regenerate_id();
require_once('dbints.php');
require_once('genral_info.php');
$options = [
    'cost' => 11,
    'salt' => mcrypt_create_iv(52, MCRYPT_DEV_URANDOM),
];

$nameErr = $emailErr = $contactErr=$passErr="";
$name = $email = $contact="";
$err=0;


$username=htmlentities($_POST['u_name']);
$useremail=htmlentities($_POST['u_email']);
$usercontact=htmlentities($_POST['u_contact']);
$userpass=htmlentities($_POST['u_password']);




$stmt = $conn->prepare("SELECT * FROM user_reg WHERE user_email=?");
$stmt->bind_param("s", $useremail);
$stmt->execute();
$result = $stmt->get_result();
if($result->num_rows > 0) {
 
 $_SESSION['already']="You are already register";
 header('Location: ../login.php');
 die();
}


$stmt->close();





if($err==0)
{
//User Name Validation
		if(empty($username))
		{
			 $_SESSION['nameErr'] = "Name is required";
			 $err=1;
		}
		else
		{
			$username=trim($username);
			$username=stripslashes($username);
			$username=htmlspecialchars($username);

				if (!preg_match("/^[a-zA-Z ]*$/",$username))
				{
		 			 $_SESSION['nameErr']="Only letters and white space allowed";
		 			 $err=1;
				}
		}

//User Email Validation

		if(empty($useremail))
		{
			 $_SESSION['emailErr'] = "Email is required";
			 $err=1;
		}
		else
		{
			$useremail=trim($useremail);
			$useremail=stripslashes($useremail);
			$useremail=htmlspecialchars($useremail);

				if (!filter_var($useremail, FILTER_VALIDATE_EMAIL))
				{
		 			 $_SESSION['emailErr'] ="Only letters and white space allowed";
		 			 $err=1;
				}
				
		}

//User Contact Number Validation

		if(empty($usercontact))
		{
			 $_SESSION['contErr'] = "Contact Number is required";
			 $err=1;
		}
		else
		{
			$usercontact=trim($usercontact);
			$usercontact=stripslashes($usercontact);
			$usercontact=htmlspecialchars($usercontact);

				if (!preg_match('/^\d+$/',$usercontact) )
				{
		 			 $_SESSION['contErr'] ="Contact numer is not valid";
		 			 $err=1;
				}
				$lengh = strlen($usercontact);
				if ($lengh!=10)
				{
		 			 $_SESSION['contErr'] ="Enter Valid Contact Number";
		 			 $err=1;
				}
		}

//User Password Validation

		if(empty($userpass))
		{
			 $_SESSION['passErr'] = "Password is required";
			 $err=1;
		}
		else
		{
			$userpass=trim($userpass);
			$userpass=stripslashes($userpass);
			$userpass=htmlspecialchars($userpass);
				if (strlen($userpass)<6)
				{
		 			 $_SESSION['passErr'] ="Please Enter Atleast 6 Charactor or Digit";
		 			 $err=1;

				}

		}

//redirect to director

				if($err==1)
				{
				$_SESSION['username']=$username;
				$_SESSION['useremail']=$useremail;
				$_SESSION['usercontact']=$usercontact;
					header('Location: ../reg.php');
					die();
				}
}



$pword=password_hash('$userpass', PASSWORD_BCRYPT, $options);


//start information enter in data base
	if($err==0)
	{


		//Unset field value sessions;
		if (isset($_SESSION['username']) || isset($_SESSION['useremail']) || isset($_SESSION['usercontact'])|| isset($_SESSION['userpass'])){
		session_unset('username');
		session_unset('useremail');
		session_unset('usercontact');
		}
		// Unset error sessions
		if(isset($_SESSION['passErr']) || isset($_SESSION['contErr']) || isset($_SESSION['emailErr']) || isset($_SESSION['nameErr'] ) )
		{
		session_unset('passErr');
		session_unset('contErr');
		session_unset('emailErr');
		session_unset('nameErr');
		}
	}

//information related to IP;
    $c_code = $CountryCode;
    $country = $Country;
    $state = $State;
    $s_code = $StateCode;
    $city = $City;

//Information related to Device
	$browser = $browser ." ".$bversion;
 	$os = $os_platform ;
 	$regdate= date("d-m-Y");

// code for insert into database
$stmt = $conn->prepare("INSERT INTO user_reg (user_name, user_email, user_contact, user_password, reg_date, user_browser, user_os, user_countrycode, user_country, user_statecode, user_state, user_city) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("ssssssssssss", $username, $useremail, $usercontact, $pword, $regdate, $browser, $os, $c_code, $country,$s_code,$state,$city);
if($stmt->execute())
{
	$_SESSION['useremail']=$useremail;
	header('Location: ../');
}
$stmt->close();






/*

$pword=password_hash("admin31december", PASSWORD_BCRYPT, $options);

$admin="insert into admin_ac(admin_user,admin_password) values ('$uname','$pword')";

if(mysqli_query($conn,$admin))
{
	echo "successfull inserted";
}
else{
	echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
*/
?>

#6

Thank you its working…!!!
But I want to know what changes you done.

I have no time now to review all card.

Please tell me what you did?


#7

Ok got it you just put space.
Is i am right?


#8

Yep.
I also added
ob_start();


#9

Thank you very much.


#10

Do not forget to read this giveaway topic :wink:
https://www.000webhost.com/forum/t/wotm-get-1-free-website-user-voting-and-showcase-website/82540/


#11