When I first needed to create a application that relocated to another page I found out about the header() function in php. which you can send a relocation to the header. I thought to myself, ok, sweet, this is easy. So I put in the function and location and I got this error
Warning: Cannot modify header information - headers already sent by (output started at C:\www\apache\htdocs\application.php:55) in C:\www\apache\htdocs\application.php on line 59
I was told that I have to put the header function at the very top of the page. Before there is any spaces. So i did move move the header function in a tag at the very top of the document. even before any html script could be written out. However, there is one tag that starts before the tag with the header in it begins if you look below, you will see a tage with a session_start() function that begins before the second tag starts. the second tag has the header() in it, but yet there are strings with spaces before it and spaces in general within the tag, yet the header() function still works and relocates the browser to another page. here is the block of code. Dont pay any attention to nothing but where the header is placed and the comments
<?PHP session_start(); ?>
<?php if ($_POST['loginName'] != "" && $_POST['password'] !=""){
require_once('Connections/ok.php');
mysql_select_db($database_ok,$ok);
// <--- spaces here, not sure if thats
// what they meant
$query = sprintf("SELECT firstName, loginName, passWord, USERID FROM usersWHERE loginName = '%s'",mysql_real_escape_string($_POST['loginName']));
//above is a string of code with spaces not sure if they meant by those
//types of strings
$results = mysql_query($query) or die("Query failed ($query): " . mysql_error());
$check = mysql_fetch_assoc($results);
if (strcasecmp($check['loginName'],$_POST['loginName']) == 0
&& strcmp($check['passWord'],$_POST['password']) == 0
&& !$check['passWord']== "" && !$check['loginName'] == "") {
$_SESSION['user'] = array(
'firstname'=>$check['firstName'],
'userID'=>$check['USERID'],
'loginName'=>$check['loginName']);
empty($_POST['loginName']);
empty($_POST['passWord']);
mysql_close($ok);
header('location: http://localhost/admin.php');//<-----header right here
//exit();
}
else { header('location: http://localhost/admin.php'); //<-----header right here}
}?>
This block of code works , yet there is spaces in there. Im confused, someone explain please
and yes i did place this tag at the very top of the page.
My question is...
Are there not suppose to be any spaces within a php tag
or are there not suppose to be any spaces within the html document or the html content. because there is spaces in the string that was placed in the varible. there was spaces within the tag. yet it worked