1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Please help : code for redirection in php.

Discussion in 'PHP' started by admans, Sep 23, 2005.

  1. #1
    Hey people,

    I need to make 1 php page which redirects to my page.

    Ne help would be highly appreciated.

    Thanx.

    Admans.


    P.S : i dont want html based page. I want only .php page which when visited redirects to page on my site.
     
    admans, Sep 23, 2005 IP
  2. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #2
    <?php
    header("Location: http://www dot yoursite dot com/");
    ?>


    or

    print '<script language="Javascript" type="text/javascript">
    <!-- Hide script
    //<![CDATA[
    window.location.href="http://www dot your site dot com/"
    //]]> End script hiding -->
    </script>';
     
    Weirfire, Sep 23, 2005 IP
  3. Old Welsh Guy

    Old Welsh Guy Notable Member

    Messages:
    2,699
    Likes Received:
    291
    Best Answers:
    0
    Trophy Points:
    205
    #3
    The only safe way to handle redirects is to 301 them. Scripted redirects are commonly used by spammers so be VERY careful
     
    Old Welsh Guy, Sep 23, 2005 IP
  4. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #4
    Maybe they don't know how to?
     
    Weirfire, Sep 23, 2005 IP
  5. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #5
    If you want to do a 301 redirect with PHP, you need to add the proper header() function. For example:

    <?php
    	header("HTTP/1.1 301 Moved Permanently");
    	header("Location: http://www.digitalpoint.com/");
    ?>
    PHP:
     
    digitalpoint, Sep 23, 2005 IP
    exam likes this.
  6. Old Welsh Guy

    Old Welsh Guy Notable Member

    Messages:
    2,699
    Likes Received:
    291
    Best Answers:
    0
    Trophy Points:
    205
    #6
    And done as shawn posted, you will not be here in a few months asking 'where did my site go' am I banned by Google Yahoo! etc :D
     
    Old Welsh Guy, Sep 23, 2005 IP
  7. admans

    admans Peon

    Messages:
    870
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanx a lot people.....really helpfull personalities here...5 stars to this forum..long live DP....okz okz..m getting little too excited :p

    Newayz..thanx all for help me out. I am gonna do the permanent redirect.

    Again. Thanx all.

    Admans.
     
    admans, Sep 23, 2005 IP
  8. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #8
    Do you realise you have the bold lock on?
     
    Weirfire, Sep 23, 2005 IP
  9. admans

    admans Peon

    Messages:
    870
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Im getting error on this :

    Warning: Cannot modify header information - headers already sent by (output started at xxcxxxxxxxxxxxxxxxx/board/index.php:1) in xxxcxxxxxxxxxxxxxxxx//board/index.php on line 3


    Sorry for that post in bold.
     
    admans, Sep 23, 2005 IP
  10. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #10
    Put the redirection code before anything that will spit anything out to the end user (before any echo, print, etc. functions). Once your script outputs anything to the end-user's browser, the headers have already been sent and cannot be set.
     
    digitalpoint, Sep 23, 2005 IP
  11. Old Welsh Guy

    Old Welsh Guy Notable Member

    Messages:
    2,699
    Likes Received:
    291
    Best Answers:
    0
    Trophy Points:
    205
    #11
    have you got more than one set of headers on the page?
     
    Old Welsh Guy, Sep 23, 2005 IP
  12. johnt

    johnt Peon

    Messages:
    178
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #12
    You can use output buffering so that you can decide when the headers get sent. That way you can still use redirects even if you are halfway through your page.

    John
     
    johnt, Sep 24, 2005 IP