Afficher un message
Vieux 26/10/2007, 17h47   #8
aaron.forsander@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: php redirect doesnt work

On Oct 7, 8:21 pm, Jack <accpac...@hotmail.com> wrote:
> Hi,
> I have a problem that I've been stuck on for while now.
> Here is my code
>
> <html>
> <head>
> <title>Login</title>
> </head>
> <body>
> <h2>Login</h2>
> <?php
> if ( (isset($_POST['uname'])) && (isset($_POST['pass'])) ){
> include '../dbConn.inc';
> $uname = $_POST['uname'];
> $pass = sha1($_POST['pass']);
>
> $dbResult = mysql_query("select uid from users where
> username='$uname' and password='$pass'", $dbh);
> mysql_close($dbh);
> if (mysql_num_rows($dbResult) < 1){
> print "Invalid username or password.";
> }else{
> session_start();
> $_SESSION['uid'] = mysql_result($dbResult, 0, 'uid');
> header('Location: main.php');
> }}else{
>
> ?>
> <form method="post" action="login.php">
> <table border="0">
> <tr>
> <td>Username:</td>
> <td><input type="text" name="uname" size="20"/></td>
> </tr>
> <tr>
> <td>Password:</td>
> <td><input type="password" name="pass" size="20"/></td>
> </tr>
> <tr>
> <td><input type="submit" value="Submit" name="login"/></td>
> </tr>
> </table>
>
> </form>
>
> </body>
> </html>
> <?php}
>
> ?>
>
> For some reason, the page doesn't get redirected to main.php. Can
> anyone me with this.
>
> ps. there is no spaces after ?> at the bottom of the code.
>
> Thanks


You've already sent the HTTP headers. You can't send them twice. You
need to call 'header()' BEFORE you output anything or else it will not
work.

  Réponse avec citation
 
Page generated in 0,05773 seconds with 9 queries