Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 363
  • Last Modified:

PHP Redirect to another page

Good day everyone!
     I have trouble redirect my users to another page if they didn't input the username or password. Following is the part of my code and the warning I got!

if(!isset($fname) ||!isset($fssn) )
{
header("Location:http://www.thesloopygroup.com/tenants.php");
 exit();
}
elseif(empty($fname) ||empty($fssn))
{

header("Location:http://www.thesloopygroup.com/tenants.php");

}
else
{
  ...........
}

Here is the warning I got:

Warning: Cannot add header information - headers already sent by (output started at /home/thesloo/public_html/tenants1.php:10) in /home/thesloo/public_html/tenants1.php on line 22

Any suggestion will be appreciated!

Ben






0
pangyen
Asked:
pangyen
1 Solution
 
etrain01Commented:
Make sure this is before any html tags.  This is probably why you are getting the error.

etrain01
0
 
spencerslamCommented:
etrain01 is right there cant be anything (including blank space) outputted to the browser before the header command.
0
 
Big_Red_DogCommented:
You should make sure the very very first line of your HTML is "<?php" and put logic in to get yourself to your header() without anything being output to the browser, including a blank line!  You can output HTML within your PHP logic as long as it isn't within the block for the header().   See below how there is absolutely nothing output to the broswer before the header() because the logic prevents it.

Example:

<?php
if (isset($_SESSION['uname'])) {
?>
<HTML>
<HEAD>
</HEAD>
<BODY>
Welcome <?=$_SESSION['uname']?>
<?php
} else {
    header( "Location: myotherpage.php" );
}
?>
</BODY>
</HTML>
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
pangyenAuthor Commented:
Hi!
Thank you for the help!

Ben
0
 
Big_Red_DogCommented:
I forgot to write the exit(); after the header(), but you already had it.  Just don't forget it, and thank you!
0
 
tannernettCommented:
how do i target the redirect to go to "_top" to get rid of other frames?
-tanner
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now