I have a register form for member. But when member registered in my website i want automatically open wellcome.php page. I know it is header("Location: wellcome.php");
but i did it and nothing happen. What can i do? Registered is successfully But does not redirect.
<?php
include("includes/connect.php");
session_start();
if(isset($_POST['submit_bregister'])){
$name = $_POST['name'];
$surname = $_POST['surname'];
$email = $_POST['email'];
$re_email = $_POST['re_email'];
$password = sha1($_POST['password']);
$vergi_num = $_POST['vergi_num'];
$sirket_kategorisi = $_POST['sirket_kategorisi'];
$is_kategorin = $_POST['is_kategorin'];
$ulke = $_POST['ulke'];
$sehir = $_POST['sehir'];
if($name==''){
echo"<div class='error_name'>Adınız alanını boş bıraktınız!</div>";
exit();
}
if($surname==''){
echo"<div class='error_name'>Soyadınız alanını boş bıraktınız!</div>";
exit();
}
if($vergi_num==''){
echo"<div class='error_name'>Vergi numaranızı girmediniz!</div>";
exit();
}
if(strlen($vergi_num)>11 || strlen($vergi_num)<0){
echo"<div class='error_name'>Vergi numaranız en az çok 11 hane olabilir!</div>";
exit();
}
if($sirket_kategorisi==''){
echo"<div class='error_name'>Şirket Kategorisi alanını boş bırakamazsınız!</div>";
exit();
}
if($is_kategorisi==''){
echo"<div class='error_name'>İş kategoriniz alanını boş bırakamazsınız!</div>";
exit();
}
if($ulke==''){
echo"<div class='error_name'>Yaşadığınız Ülkeyi boş bırakamazsınız!</div>";
exit();
}
if($sehir==''){
echo"<div class='error_name'>Yaşadığınız Şehir alanını boş bırakamazsınız!</div>";
exit();
}
if($email==''){
echo"<div class='error_name'>E-Mail alanını boş bıraktınız!</div>";
exit();
}
if($_POST['email'] !== $_POST['re_email']){
echo"<div class='error_name'>E-Mail Adresleriniz Eşleşmiyor!</div>";
exit();
}
$check_email = "SELECT * FROM users WHERE email='$email'";
$run = mysql_query($check_email);
if(mysql_num_rows($run)>0){
echo "<div class='error_name'>Bu E-Mail adresi kullanımda!</div>";
exit();
}
$sirket_kategorisi = (int)$sirket_kategorisi;
$query = "SELECT is_kategorisi FROM business_category WHERE id='$sirket_kategorisi'";
$res = mysql_query($query);
$row = mysql_fetch_assoc($res);
$sirket_kategorisi = $row['is_kategorisi'];
$querys ="INSERT INTO `users` (`name`,`surname`,`email`, `re_email`,`password`,`vergi_num`,`sirket_kategorisi`,`is_kategorin`,`ulke`,`sehir`)
VALUES ('$name','$surname','$email', '$re_email','$password','$vergi_num','$sirket_kategorisi','$is_kategorin','$ulke','$sehir')";
$result = mysql_query($querys) or die(mysql_error());
if($result){
header('Location: email');
exit;
}
else {
header('Location: error');
exit;
}
}
?>
PHP doesn't allow output before header becuase it will redirect to the page straight away using header()
, so there is no point outputting a message before you use it. If you try it will cause an error.
You could, however, add in the header of that page
<meta http-equiv="refresh" content="5;url='http://www.your-website.com/welcome.php'" />
The content attr is broken down into 2 sections time(sec) and url i.e.
content="(time in seconds) ; url='(url)'"
You can change either of these, however, make sure you keep them both inside content=""
The headers cannot be sent after there is any output on the page. The echo is an output, so you cannot send any new headers – in you case the Location header.
You should have the redirect before the echo.
Are you sure this header("Location: wellcome.php"); is at the end of your code?
What i mean with that is for example if you have an if what waits for the Get argument, something like:
if(isset($_GET['register']){
//... code for registration
}
please make sure that the header("Location: wellcome.php"); is at the end of if but inside of the bracket, and its good to use exit(); after the header.
Also you cant echo something before the header();, you should have an error when you do that, check if you are getting one.
Some of your code will help a lot to figure whats wrong.
Remember that header()
must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header()
is called. The same problem exists when using a single PHP/HTML file.
<html>
<?php
/* This will give an error. Note the output
* above, which is before the header() call */
header('Location: http://www.example.com/');
exit;
?>
Normally something like this will result in a Cannot modify header information - headers already
warning unless you don't have error/warning reporting turned on.