Need Help With PHP Redirect

3 replies
Hi

I am no coder so I really could use some help to add php redirect code to my site that i can customize to do different tasks.

For example

Method 1 :- Visitor lands on my page and after a specified time (eg 10 secs) is redirected to a specified url in the same browser tab.

Method 2 :- Visitor lands on page and and a redirect opens in a new tab keeping original page still open.

Method 3 :- Visitor lands on page and redirect opens in new browser window keeping original page open.

I know i might be asking a lot but i have tried searching for the method but just got very confused. Any help will be much appreciated.

Thanks in advance
#php #redirect
  • Profile picture of the author Brandon Tanner
    Method 1...
    Code:
    <?php
    header("refresh:10;url=targetpage.html"); 
    ?>
    If you want to serve any HTML content during this 10 seconds, you will have to put it after the php code, otherwise you will get a "headers already sent" error.

    Regarding methods 2 & 3... I don't think PHP provides a function to do this, but it's a simple task using HTML code...
    Code:
    <a href="targetpage.html" target="_blank">
    Keep in mind though that the "target" attribute is deprecated and unreliable (depending on your user's browser and configuration, it might open in a new tab, or a new window, or the same tab).
    Signature

    {{ DiscussionBoard.errors[4966698].message }}
    • Profile picture of the author gtownfunk
      You can also accomplish Method 1 and Method 2 as well as sometimes Method 3 via Javascript. Like BT said, the specific action that occurs is going to be limited by what the browser does. Generally these are user type configuration settings, ie. open new browsers in a tab instead.. for the sake of user preference and to control web pages/apps/malware that open too many windows.
      Signature
      {{ DiscussionBoard.errors[4966805].message }}
  • Profile picture of the author pfreelancer
    This would be another way to do it, just add it to the <head> html on your page.

    Code:
    <head> <meta http-equiv="refresh" content="5; URL=thankyou.htm"> </head>
    {{ DiscussionBoard.errors[4971974].message }}

Trending Topics