Page 1 of 1
header ERROR, when checking user validity
Posted: Fri Apr 09, 2004 11:06 am
by bironeb
When Checking for the Validity of user and valid != "yes" i get this error:
Warning: Cannot modify header information - headers already sent by (output started at c:\apache group\apache\htdocs\inventory\do_delrecord.php:3) in c:\apache group\apache\htdocs\inventory\do_delrecord.php on line 4
Here is the code:
Code: Select all
//check for validity of user
if ($_SESSION['valid'] != "yes") {
header("Location:http://byron/inventory/inventory_menu.php");
exit;
}
Any Ideas? or possible better suggestions to check for validity ?
Posted: Fri Apr 09, 2004 11:07 am
by allenmak
Have you got any spaces before having <?php?
Posted: Fri Apr 09, 2004 11:09 am
by bironeb
Yes, This is the top part of my code:
Code: Select all
<?
//check for required form variables
if (!$_POST['user_name']) {
header("Location:http://byron/inventory/pick_delrecord.php");
exit;
} else {
//if form variables are present,start a session
session_start();
}
//check for validity of user
if ($_SESSION['valid'] != "yes") {
header("Location:http://byron/inventory/inventory_menu.php");
exit;
}
?>
Posted: Fri Apr 09, 2004 11:10 am
by allenmak
Please delete them.
It is because the spaces before <?php will be considered as webpage content.
You cannot send any webpage content before header.
Posted: Fri Apr 09, 2004 11:13 am
by bironeb
Code: Select all
<?php<? if ($_SESSION['valid'] != "yes") {
header("Location:http://byron/inventory/inventory_menu.php");
exit;
}
//check for required form variables
if (!$_POST['user_name']) {
header("Location:http://byron/inventory/pick_delrecord.php");
exit;
} else {
//if form variables are present,start a session
session_start();
}
//set up table and database names
$db_name ="Inventory";
$table_name ="client_hardware";
//connect to server and select database
$connection =@mysql_connect("localhost","byron","byronb") or die(mysql_error());
$db =@mysql_select_db($db_name,$connection) or die(mysql_error());
//build and issue query
$sql = "DELETE FROM $table_name WHERE user_id ='".$_POST['user_id']."'";
$result = @mysql_query($sql,$connection) or die(mysql_error());
?>
<HTML>
<HEAD>
<TITLE>Inventory Management System: Record Deleted</TITLE>
</HEAD>
<BODY bgcolor="B1D3EC">
<h2><em>Delete a Record - Record Deleted</em></h2>
<P><? echo "$_POST[user_name] $_POST[user_id]"; ?> has been deleted from <? echo "$table_name"; ?></p>
<br><p><a href="inventory_menu.php">Return to Main Menu</a></p>
</BODY>
</HTML>
?>
I changed the top two around and still get the errors.. I have no spaces before <? and i get this:
Notice: Undefined variable: _SESSION in c:\apache group\apache\htdocs\inventory\do_delrecord.php on line 1
Warning: Cannot modify header information - headers already sent by (output started at c:\apache group\apache\htdocs\inventory\do_delrecord.php:1) in c:\apache group\apache\htdocs\inventory\do_delrecord.php on line 2
Posted: Fri Apr 09, 2004 11:31 am
by allenmak
may i know what
Code: Select all
<?php
$_SESSION['valid'] != "yes"
?>
is?
Posted: Fri Apr 09, 2004 11:38 am
by bironeb
It is the validity of my session in the cookie... does this answer your question?
Posted: Fri Apr 09, 2004 11:40 am
by allenmak
I guess the header problem has already been solved.
But because your $_SESSION["valid"] is not defined. It shows error message which makes PHP parse out some content before the header is sent out.
Posted: Fri Apr 09, 2004 11:42 am
by bironeb
Hmmm... thats very interesting... I may have to go at it another way maybe. Any Ideas?
Posted: Fri Apr 09, 2004 12:11 pm
by magicrobotmonkey
if(isset($_SESSION['valid']))
if($-SESSION['valid'])
header(whatever)
And I would use the reserved words true and false or 1 and 0 instead of 'yes' and 'no', that way you can simply write
if($_SESSION['valid']);
Posted: Fri Apr 09, 2004 1:33 pm
by John Cartwright
doesnt session_start(); have to be on line1?
Posted: Fri Apr 09, 2004 4:01 pm
by twigletmac
Phenom wrote:doesnt session_start(); have to be on line1?
Yup, without session_start() you can't access the session variables.
Mac