...

View Full Version : redirecting a page when wrong user and pass



jarv
05-15-2008, 11:11 AM
I get the error: headers already sent





if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
header("location:index.html");

}

abduraooft
05-15-2008, 11:18 AM
//echo "Wrong Username or Password";
header("location:index.html");

You can't echo/output something before header()

jarv
05-15-2008, 11:24 AM
i swapped them around, still doesn't work

Fou-Lu
05-15-2008, 03:40 PM
It never will mate, as soon as you send a header redirection it will force the page to the new location - you will never get the output from the echo. Instead, redirect them to a page that includes the error message, or use the $_SESSION (from your last post) or $_GET, to pass an error code back to the login to display the results. Something like:


header('Location: index.php?ec=1');

Then back in index.php


<?php
// some stuffs

if (isset($_GET['ec']))
{
switch($_GET['ec'])
{
case 1:
echo 'Invalid username specified';
break;
case 2:
echo 'Invalid password specified';
break;
}
}
// login stuff.

Or whatever you want to do with the feedback.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum