?
Solved

PHP Redirect to another page

Posted on 2003-02-25
6
Medium Priority
?
362 Views
Last Modified: 2008-02-01
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
Comment
Question by:pangyen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 5

Expert Comment

by:etrain01
ID: 8020024
Make sure this is before any html tags.  This is probably why you are getting the error.

etrain01
0
 

Expert Comment

by:spencerslam
ID: 8020085
etrain01 is right there cant be anything (including blank space) outputted to the browser before the header command.
0
 
LVL 7

Accepted Solution

by:
Big_Red_Dog earned 80 total points
ID: 8020159
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:pangyen
ID: 8020365
Hi!
Thank you for the help!

Ben
0
 
LVL 7

Expert Comment

by:Big_Red_Dog
ID: 8020406
I forgot to write the exit(); after the header(), but you already had it.  Just don't forget it, and thank you!
0
 

Expert Comment

by:tannernett
ID: 8721614
how do i target the redirect to go to "_top" to get rid of other frames?
-tanner
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question