You are here: Re: php redirect doesnt work « All PHP « IT news, forums, messages
Re: php redirect doesnt work

Posted by aaron.forsander@gmail.com on 10/26/07 16:47

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 help 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.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация