I have solved the above one but i still failed to solve this one..it's much more complicated..please help! The program flaws are 1st, the users need to be authenticated and below are most parts of the codes to authenticate the users.., once the users are authenticated, then the users are allow to use Shopping Cart..and the function for shopping cart that has session_start() is function abc($USERNAME). The errors are the similar like above!
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<?php
if (!$USERNAME || !$PASSWORD ) {
fieldsBlank();
die();
}
if ( isset ( $NewUser ) ) {
if ( !( $file = fopen( "cart_password.txt", "append" ) ) ) {
print( "<title>Error</title></head><body>
Could not open password file
</body></html>" );
die();
}
fputs( $file, "$USERNAME,$PASSWORD\n" );
userAdded( $USERNAME );
}
else {
if ( !( $file = fopen( "cart_password.txt","read" ) ) ) {
print( "<title>Error</title></head>
<body>Could not open password file</body></html>" );
die();
}
$userVerified = 0;
while ( !feof( $file ) && !$userVerified ) {
$line = fgets ( $file,255);
$line = chop ( $line );
$field = split ( ",",$line,2);
if ( $USERNAME == $field[0] ) {
$userVerified = 1;
if ( checkPassword( $PASSWORD, $field) == true )
accessGranted( $USERNAME );
else
wrongPassword();
}
}
fclose( $file);
if ( !$userVerified )
accessDenied();
}
function checkPassword ( $userpassword, $filedata )
{
if ( $userpassword == $filedata[1] )
return true;
else
return false;
}
?>
<?php
function abc($USERNAME)
{
require_once("cart.php");
session_start();
if(!isset($USERNAME))
{
$USERNAME = new cart;
session_register("USERNAME");
}
$USERNAME->add_item(1, 3, 5);
$USERNAME->add_item(2, 7, 10);
$USERNAME->add_item(3, 4, 7.5);
$USERNAME->modify_qty(2, 3, 10);
$USERNAME->delete_item(3);
$total_items = $USERNAME->num_items();
}
?>
<?php
function userAdded( $name)
{
print("<title>Thank You</title></head>
<body style = \"font-family: arial;
font-size: 1em; color:blue\">
<strong>You have been added to the user list, $name. <br />Enjoy the site.</strong>" );
}
function accessGranted( $name )
{
print ( "<title>Thank You</title></head>
<body style = \"font-family: arial;
font-size: 1em; color:blue\">
<strong>Permission has been granted, $name. <br />
Enjoy the site.<br /></strong>" );
//echo '<br /><a href="cart_test.php?' . $name . '">Proceed to Shopping Cart</a>';
//echo '<br /><a href="trytry.php">Proceed to Shopping Cart</a>';
abc($name);
}
function wrongPassword()
{
print( "<title>Access Denied</title></head>
<body style = \"font-family: arial;
font-size: 1em; color:red\">
<strong>You entered an invalid password.<br />Access has been denied.</strong>" );
}
function accessDenied()
{
print ("<title>Access Denied</title></head>
<body style = \"font-family: arial;
font-size: 1em; color:red\">
<strong>You were denied access to this server.<br /></strong>" );
}
function fieldsBlank()
{
print ( "<title>Access Denied</title></head>
<body style = \"font-family: arial;
font-size: 1em; color:red\">
<strong>Please fill in all form fields.<br /></strong>" );
}
?>
</head>
<body>
Shopping Cart <br>
Number of Items: <?php echo $total_items ?> <br>
Subtotal Cost: <?php echo $user_cart->sub_total; ?>
</body>
</html>