|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
Cannot modify header information
i get this error when i try to login:
Warning: Cannot modify header information - headers already sent by (output started at C:\XITAMI\webpages\do_authuser.php:2) in C:\XITAMI\webpages\do_authuser.php on line 22 heres the code: Code:
<?php
if ((!$_POST[username]) || (!$_POST[password])) {
include("show_login.html");
exit;
}
$table_name = "auth_users";
$db_name = "users";
$connection = @mysql_connect("localhost", "root", "")
or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
$sql = "SELECT * FROM $table_name WHERE username = '$_POST[username]' AND password = password('$_POST[password]')";
$result = @mysql_query($sql,$connection) or die(mysql_error());
$num = mysql_num_rows($result);
if ($num != 0) {
$cname = "auth";
$cvalue = "ok";
$cexpire = time()+86400;
$cdomain = "localhost";
ob_start();
setcookie($cname, $cvalue, $cexpire, "/", $cdomain, 0);
ob_end_flush();
$display_block = "
<p><strong>You have successfuly logged in!</strong></p>
<p><strong>Pages:</strong></p>
<P><a href=\"authpageA.php\">Page1</a><br>
<a href=\"authpageB.php\">Page2</a></p>";
} else {
echo "<P><Strong>Invalid username or password, please try again.</strong?</P>";
include("show_login.html");
}
?>
<?
echo "$display_block";
?>
can any one help??? |
|
#2
|
||||
|
||||
|
setcookie is a header function, which means it has to be called before any output is generated. Easiest way to solve this is to move the ob_start() to the beginning of your code.
good luck. |
|
#3
|
|||
|
|||
|
thanks, but that doesnt leave a cookie, or maybe my script to check for the cookie is wrong:
Code:
<?php
if ($_COOKIE[auth] == "ok") {
echo "You are now on page one.";
} else {
echo "You are not logged in, please do so.";
include("show_login.html");
}
?>
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > Cannot modify header information |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|