redirect url

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jaylin
Forum Commoner
Posts: 68
Joined: Fri Nov 18, 2005 4:44 am

redirect url

Post by jaylin »

i want to redirect a page after a checking.
for e.g

if (a == a)
// redirect to http://www.abc.com
else
//redirect to http://www.bbb.com

regards,
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Code: Select all

<?
if ($a == $a)
{
    header("location: thispage.php");
    exit;
}
else
{
    header("location: thisotherpage.php");
    exit;
}
jaylin
Forum Commoner
Posts: 68
Joined: Fri Nov 18, 2005 4:44 am

Post by jaylin »

i goot this error
Warning: Cannot modify header information - headers already sent by (output started at c:\Inetpub\wwwroot\toniwin\automobile.php:4) in c:\Inetpub\wwwroot\toniwin\automobile.php on line 32
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Have a look at this thread:
viewtopic.php?t=1157

Mac
jaylin
Forum Commoner
Posts: 68
Joined: Fri Nov 18, 2005 4:44 am

Post by jaylin »

i have seen the post. but, i have no idea to solve my problem. i think it is better to post my code and let expert solve the problem for me.

Code: Select all

if (isset($_REQUEST['action']) && $_REQUEST['action']=='submitted')
    {
        if (isset($_REQUEST['memberid']))
        {
            $link =  mysql_connect('mydatabase','myuser','mypassword');
            if (!$link)
                echo 'Can\'t open the database';
            else
            {
                $db = mysql_select_db('mydbase');
                if (!$db)
                {
                  echo 'DataBase Error : ' . mysql_error();
                }
                $sql = "SELECT * FROM member WHERE memberID=" . $_REQUEST['memberid'];
                $query = mysql_query($sql);
                $num_row = mysql_num_rows($query);
                if ($num_row >0 )
                {
    header("Location: thispage.php");
                 }
                else
                    echo 'get out of here';
            }

plz help me.
twigletmac wrote:Have a look at this thread:
viewtopic.php?t=1157

Mac
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

there has to be more code above that wether it be html or anything. if you output ANYTHING to the browser before you call header() you will get that error. post all the code before that
jaylin
Forum Commoner
Posts: 68
Joined: Fri Nov 18, 2005 4:44 am

Post by jaylin »

thz for all. now i fixed it. :lol: :lol: :lol: :lol:
Post Reply