i have started a session on using this php code
login.php
<?php
include("auth.php");
echo "<br><br><br><br><br><br><center style=\"font-family:arial;font-size:200%;color:rgb(57,47,107)\"><b><i>Directing you to the main page, please wait!</i></b></center>";
echo "<META HTTP-EQUIV=\"refresh\" content=\"3; URL=start.html\">";
?>
auth.php
<?php
// start session
session_cache_limiter('public');
session_start();
global $username;
// convert username and password from _POST or _SESSION
if($_POST["username"])
{
$username=$_POST["username"];
$password=$_POST["password"];
}
elseif($_SESSION["username"])
{
$username=$_SESSION["username"];
$password=$_SESSION["password"];
}
// start and register session variables
session_register("username");
session_register("password");
// connect to database
include("connect.php");
// query for a user/pass match
$result=mysql_query("select customer.username, passes.password from customer, passes where customer.username='" . $username . "' and passes.password='" . $password . "'");
// retrieve number of rows resulted
$num=mysql_num_rows($result);
// print login form and exit if failed.
if($num < 1){
session_destroy();
echo "<br><br><br><b><i><center style=\"font-family:arial;font-size:125%;color:rgb(57,47,107)\">You are not authenticated, please login below.</center></i></b><br>
<form method=POST action=login.php>
<table width='100%' border=0>
<tr width='100%'><td colspan=6 align='middle'><hr></td></tr>
<tr width='100%'><td colspan=6 align='middle'><img src=\"autotrail.jpg\" width=\"886\" height=\"277\"></td></tr>
<tr width='100%'><td colspan=6 align='middle'><hr></td></tr>
<tr><td width='25%'></td><td width='12.5%'></td><td align='middle' width='12.5%'><p style=\"font-family:arial;color:rgb(57,47,107)\"><b><i>Username:</i></b></p></td><td align='middle' width='12.5%'><input type=text name=\"username\"></td><td width='12.5%'></td><td width='25%'></td></tr>
<tr><td width='25%'></td><td width='12.5%'></td><td align='middle' width='12.5%'><p style=\"font-family:arial;color:rgb(57,47,107)\"><b><i>Password:</i></b></p></td><td align='middle' width='12.5%'><input type=password name=\"password\"></td><td width='12.5%'></td><td width='25%'></td></tr>
<tr width='100%'><td colspan=6 align='middle'><input type=submit value='Login' style=\"font-family:arial\"></td></tr>
<tr width='100%'><td colspan=6 align='middle'><a style=\" font-family:arial;font-size:10px:\" href='' onclick='javascript: void(window.close()); return false;'>Close Window</a></td></tr>
</form>";
exit;
}
?>
on my site i wan to use a 'shopping cart' and obvisously i would like to use the session id for distinguishing the carts from another
i am trying to do the following:
<?php
function GetCartID(){
if(isset($_COOKIE["cartID"])){
return $_COOKIE["cartID"];
} else {
setcookie("cartID", $session_id(),time()+((3600*24)*30));
return $session_id();
}
}
?>
the above function is declared in an inc file of mine
when this functon is called, i get the following error:
Warning: Cannot add header information - headers already sent by (output started at c:\apache\htdocs\project\cart.php:1) in c:\apache\htdocs\project\db.php on line 8
line 8 is the setcookie line.
can anyone show me where i am going wrong???