|
|
|
#1 (permalink) |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 (permalink) |
|
Messages: n/a
Hébergeur: |
Jack wrote:
> Hi, > I have a problem that I've been stuck on for while now. > Here is my code > <snipped> Jack, First of all, enable all errors and display errors in your PHP.INI file. If you don't have access to this file, you can use ini_set to set them, but it's much easier to do it in the php.ini file (also this way works even if you have syntax errors in your code). Once you get this, I'm pretty sure you'll get a message about "header already sent...". I don't remember the exact message off hand (you'd think I would, the number of times I've seen it! :-) ), but it comes because you've send output before this time. It could only be blank space - but you've sent SOME data. And you should also get a message indicating "output started in file xxx at line yyy". This is where you need to took to find why output has previously been sent. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|
|
#3 (permalink) |
|
Messages: n/a
Hébergeur: |
"Jerry Stuckle" <jstucklex@attglobal.net> wrote in message news:KoadnU6EQZ83BJTanZ2dnUVZ_vamnZ2d@comcast.com. .. > Jack wrote: >> Hi, >> I have a problem that I've been stuck on for while now. >> Here is my code >> > <snipped> > > Jack, > > First of all, enable all errors and display errors in your PHP.INI file. > If you don't have access to this file, you can use ini_set to set them, > but it's much easier to do it in the php.ini file (also this way works > even if you have syntax errors in your code). > > Once you get this, I'm pretty sure you'll get a message about "header > already sent...". I don't remember the exact message off hand (you'd > think I would, the number of times I've seen it! :-) ), but it comes > because you've send output before this time. It could only be blank > space - but you've sent SOME data. > > And you should also get a message indicating "output started in file xxx > at line yyy". This is where you need to took to find why output has > previously been sent. > > -- > ================== > Remove the "x" from my email address > Jerry Stuckle > JDS Computer Training Corp. > jstucklex@attglobal.net > ================== Jerry, I'm not a coder, but in installing php scripts I've run into that "header already sent" quite a number of times. For me, a non-coder, that meant I had to dispense with the script and go look for another. Do you know a reason or two "why?" - something that a non-coder might find and fix? Thanks in advance. |
|
|
|
#4 (permalink) |
|
Messages: n/a
Hébergeur: |
Jack wrote:
> Hi, > I have a problem that I've been stuck on for while now. > Here is my code > > <html> > <head> You see this HTML that is on the top of your page, it will prevent the header() from work, as it has to be sent before any other output from a script. You can try with adding ob_start() as the first thing on the page. -- //Aho |
|
|
|
#5 (permalink) |
|
Messages: n/a
Hébergeur: |
On Mon, 08 Oct 2007 06:17:16 +0200, "J.O. Aho" <user@example.net>
wrote: >You see this HTML that is on the top of your page, it will prevent the >header() from work, as it has to be sent before any other output from a script. I agree. Move this stuff: <html> <head> <title>Login</title> </head> <body> <h2>Login</h2> so it's above the opening form tag. one other thing you *might* have to watch out for is:- "Note: HTTP/1.1 requires an absolute URI as argument to » Location: including the scheme, hostname and absolute path, but some clients accept relative URIs. You can usually use $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a relative one yourself: " (from <http://uk3.php.net/header>) -- Locate your Mobile phone: <http://www.bizorg.co.uk/news.html> Great gifts: <http://www.ThisBritain.com/ASOS_popup.html> |
|
|
|
#6 (permalink) |
|
Messages: n/a
Hébergeur: |
Wings wrote:
> "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message > news:KoadnU6EQZ83BJTanZ2dnUVZ_vamnZ2d@comcast.com. .. >> Jack wrote: >>> Hi, >>> I have a problem that I've been stuck on for while now. >>> Here is my code >>> >> <snipped> >> >> Jack, >> >> First of all, enable all errors and display errors in your PHP.INI file. >> If you don't have access to this file, you can use ini_set to set them, >> but it's much easier to do it in the php.ini file (also this way works >> even if you have syntax errors in your code). >> >> Once you get this, I'm pretty sure you'll get a message about "header >> already sent...". I don't remember the exact message off hand (you'd >> think I would, the number of times I've seen it! :-) ), but it comes >> because you've send output before this time. It could only be blank >> space - but you've sent SOME data. >> >> And you should also get a message indicating "output started in file xxx >> at line yyy". This is where you need to took to find why output has >> previously been sent. >> >> -- >> ================== >> Remove the "x" from my email address >> Jerry Stuckle >> JDS Computer Training Corp. >> jstucklex@attglobal.net >> ================== > > Jerry, > I'm not a coder, but in installing php scripts I've run into that "header > already sent" quite a number of times. For me, a non-coder, that meant I had > to dispense with the script and go look for another. > Do you know a reason or two "why?" - something that a non-coder might find > and fix? > Thanks in advance. > > It means you've sent output (even white space) to the client before the call to session_start() or similar call. If you want to play with PHP, I highly recommend you learn some of the basics. No language is completely "plug and play". There will be problems at times, but most do not require an expert to fix. They do, however, require someone with knowledge of the language. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|
|
#7 (permalink) |
|
Messages: n/a
Hébergeur: |
>> Jerry, >> I'm not a coder, but in installing php scripts I've run into that "header >> already sent" quite a number of times. For me, a non-coder, that meant I >> had to dispense with the script and go look for another. >> Do you know a reason or two "why?" - something that a non-coder might >> find and fix? >> Thanks in advance. > > It means you've sent output (even white space) to the client before the > call to session_start() or similar call. > > If you want to play with PHP, I highly recommend you learn some of the > basics. No language is completely "plug and play". There will be > problems at times, but most do not require an expert to fix. They do, > however, require someone with knowledge of the language. > Thanks for the info and advise. |
|
|
|
#8 (permalink) |
|
Messages: n/a
Hébergeur: |
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. |
|
![]() |
| Outils de la discussion | |
|
|