Thanks guys.
I think the best thing to do is to just send you an example of my code so you can see for yourselves what my problem is.
Basically, I have been building a client a customer review application for there website. Its just an area where customers can leave testimonials.
But there is only two files we need to look at in order to pinpoint where I am going wrong when using the header() function.
Below is the code where I actually use the header function:
file name: common.inc.php:
<?php
require_once "../config.php";
require_once "../dataObjectClass.php";
require_once "../testimonialClass.php";
require_once "adminClass.php";
function checklogin(){
session_start();
if( !$SESSION["user"] ){
!$SESSION["user"] = "";
header( "Location: login.php" );
exit;
}
}
?>
......... the above document has absolutely no spaces at all before or after the opening and closing php tags. And I have just been really careful to eliminate ANY spaces. And I am still having no luck.
The below document is where I include and use the above document's function:
file name: admin.php:
<?php
require_once "common.inc.php";
checklogin();
echo "<br><h1 style='text-align: center;'>Welcome Mike!<br><br>Displaying all of your reviews:</h1><br>";
echo "<h3 style='color: blue; text-align: center;'><span style='color: black;'>NOTE - </span>Click the <span style='color: red;'>'delete'</span> button under a specific review (displayed below) if you don't want it to be displayed on your website:</h3>";
echo "<h3 style='color: blue; text-align: center;'><span style='color: black;'>IMPORTANT - </span>Please be sure to <span style='color: red;'>'logout'</span> (for the safety of your website) once you have finished making edits!</h3><br>";
$testimonials = testimonial::getAllTestimonials();
echo "<hr style='margin-top: 30px;'>";
foreach( $testimonials as $testimonial ){
echo "<div style='text-align: center; margin-bottom: 30px; margin-top: 30px;'>";
echo "<b style='font-size: 25px;'>" . ucfirst($testimonial->getValue( "firstname" )) . " " . ucfirst($testimonial->getValue( "lastname" )) . "</b><br>";
echo ucfirst($testimonial->getValue( "comment" )) . "<br>";
echo "<a href='admin.php?delete=" . $testimonial->getValue( "id" ) . "'>Delete</a> <a href='logout.php'>Logout</a>";
echo "<hr style='margin-bottom: 30px; margin-top: 30px;'>";
echo "</div>";
}
echo "<br><p style='text-align: center;'><a href='logout.php' style='font-size: 30px;'>Logout</a></p><br><br>";
$deleteById = isset( $GET["delete"] ) ? (int)$GET["delete"] : "";
if( $deleteById ){
testimonial::deleteTestimonial( $deleteById );
}
?>
To explain my problem in more detail - If I am not logged in to the admin area, and i try to view the admin.php page, the above could is intended to redirect me to the login page. But what happens is I don't get redirected to the login.php page and I just stay on the admin.php page and it is just a blank page displaying nothing. I just want it to redirect to login.php.
..... As you can see, the second document does have spaces (etc). But this can't be the reason why the function (containing the header() function) in the first file (above) isn't working, can it?
I don't know where I am going wrong.
Please help me!
Paul.