phphttp-redirectphp-include

Is it wrong to use 'include' for redirecting user to another PHP file?


I have created a HTML login form which checks for email and password authentication and then redirects to the user account.

My PHP code is as below:

 <?php  

 require('connect.php');//for connection to the database.


$email = $_POST['email'];
$password = $_POST['password'];

$query = "SELECT * FROM `account` WHERE pemail='$email' and password='$password'";

$result1 = mysql_query($query) or die(mysql_error());
$usercount = mysql_num_rows($result1);




if ($usercount == 1){
include 'myaccount.php';
}


else{

echo "Invalid Details.";
echo "<a href='login.php'>Back to Login</a>";
}

Here, I have tried include to redirect to the user account...and it works fine.

Though my instructor says me that it is wrong to use include and you should implement it in another ways.

Why it is wrong to use include to redirect to the user account? I searched for it but I didn't found the answer.

plz do not discourage...thanks in advance.


Solution

  • Yes, your instructor is correct. include() is for including PHP code, not for redirecting. header() function does that, so use it. Using include() works, but that doesn't mean you should use it.

    Why shouldn't you use include?

    More problems in your code: