Would This Be A Simple PHP Redirect? Or Is It Not Possible?

10 replies
Attention programmers (or anyone with the knowledge I seek),

This may be a standard and easy thing, I dont know. But this is what I'm interested in:

I would like to have a page that redirects to another only when the person gets to the page from a specific link. If they didnt arrive at the page from that link and came from anywhere else, then the page wouldn't redirect, it would show content. Make sense? Sorry if I didn't word it well.

To put it another way:

Page 1 has a link on it to page 2. If the vistor came to page 2 from the link on page 1, page 2 would redirect to page 3. If the visitor came to page 2 from any other means than the link on page 1, then it would just show the content that I've put on it.

With the things that can be done nowadays, I would find it hard to believe that this couldn't be done, but you never know.

I did a little searching on PHP redirects and such and couldn't find quite what I was lookin for.

So can someone with knowledge of this sort of thing let me know? If it's possible, I'd like to buy the script or pay a programmer to write it and possibly install it.

Thanks,

Richard
#php #redirect #simple
  • Profile picture of the author mywebwork
    Hi Richard

    If it's acceptable to have a link from page one formatted like "http://mysite.com/page2?id=1" then it could easily be done. They key is to have an identifier at the end of the URL that identifies the link as coming from page 1. You would then trap that on page two to use it as a redirect to page 3.

    Users simply arriving at page two would not have the identifier and would not be redirected.

    Let me know if you need any assistance with this.

    Bill
    {{ DiscussionBoard.errors[1531681].message }}
    • Profile picture of the author Richard-Malcolm
      Originally Posted by mywebwork View Post

      Hi Richard

      If it's acceptable to have a link from page one formatted like "http://mysite.com/page2?id=1" then it could easily be done. They key is to have an identifier at the end of the URL that identifies the link as coming from page 1. You would then trap that on page two to use it as a redirect to page 3.

      Users simply arriving at page two would not have the identifier and would not be redirected.

      Let me know if you need any assistance with this.

      Bill
      I love this place. I just posted this question and I have already gotten 2 responses, generous and helpful ones at that.

      But, Yes I would like to have assistance with this.

      If you want to PM me, I could tell you more about what I have in mind. Then we can go from there.

      Thank you very much,

      Richard
      Signature

      Sig is having a cig.....

      {{ DiscussionBoard.errors[1531720].message }}
  • Profile picture of the author kendrickyi
    Hmm yes it should be possible. My friend did it in jsp I think.

    Like what Bill said, you need something at the back, like an SQL query thingy which he showed. I'm not sure about php, but if it were in vb I would use an if else statement like

    <html>
    <head></head>
    <body>
    <%
    if (user came from page 1) {
    redirect to page 2;
    } else {
    %>

    <h1> Welcome to page 2 </h2>

    <%
    }
    %>
    <!-- lol sorry I can't recall my syntaxes but I hope you got the logic -->
    </body>
    </html>

    I can't quite remember my syntaxes! I think you have to use a <form type="hidden"> in page 1 and a request.form in page 2.

    *Note that I'm saying this with knowledge on vb and absolutely no knowledge on php. Change the syntax accordingly*
    {{ DiscussionBoard.errors[1531700].message }}
  • Profile picture of the author rtrotter
    Richard, this is very easy. Assume the link on page 1 to page 2 is mypage2link.htm
    Use this code:

    <?php
    $refer = $_SERVER['SCRIPT_URL'];
    if (strpos($refer,"mypage2link.htm") !== false) {
    header('Location: mypage3.htm');
    exit;
    }
    ?>

    You will need to have either your httpd.conf or .htaccess file set to have htm or html processed as php. For example:

    AddType application/x-httpd-php .php .htm .html

    Of couse, if your pages are php then you can just use their urls and not worry about setting server to process html as php.

    Hope that helps,
    Rodney
    Signature

    Ping All Your Feed On Auto-Pilot
    www.kping.com

    {{ DiscussionBoard.errors[1531738].message }}
    • Profile picture of the author Tim Brownlaw
      Hi Richard,

      I've come up with a snazzy way to achieve this using PHP.

      I'm just putting on the final touches to the ebook and code but I can PM you the link if you want to get started.

      I'm upto the super tricky, not really needed, but makes life easier stuff! At this stage it's working a treat.

      So if your existing files are currently .html, are you able to change them to .php. If not I'm including a work around which involves a change to your htaccess file..but I'd have to talk to you about what you've got on your site.

      It's all tested.
      It involves uploading a file,
      adding an include statement to your existing files,
      Setting the Rules, I've explained this in the ebook
      and Bob's your aunty...

      How comfortable are you with PHP?

      Let me know if you'd like to see how I've achieved this?
      It may or may not suit your needs.

      Anyway, your post inspired it, and after 3 hours from scratch, it's nearly done.
      I'm getting quicker at this, but then my students are begging for more "Stuff".

      That's what makes the warrior forum such a grand place!

      Cheers
      Tim
      {{ DiscussionBoard.errors[1532645].message }}
    • Profile picture of the author xiaophil
      Hi, Richard.

      A couple of good solutions here, and a lot of noise too.

      I was thinking along the same lines as Rodney, not sure about SCRIPT_URL though. Maybe:

      $refer = $_SERVER['HTTP_REFERER'];

      Cheers,
      Phil
      {{ DiscussionBoard.errors[1533046].message }}
  • Profile picture of the author rtrotter
    Phil,

    That is correct, it should be HTTP_REFERER in this case. I actually pulled that from a script I wrote to run nice clean affiliate links through my 404 page. In that case you use SCRIPT_URL. I create affiliate links with whatever page name I want and then in the script for 404 page it detects the url and redirects using properly coded affiliate url.

    Thanks for points out that change to my post.

    Rodney
    Signature

    Ping All Your Feed On Auto-Pilot
    www.kping.com

    {{ DiscussionBoard.errors[1533080].message }}
  • Profile picture of the author Richard-Malcolm
    Hey everyone,

    Thanks for the amazing response.

    When it comes to PHP code, or any code for that matter, Im a complete newb. I can do some easy html, build simple sites and ftp, etc... But when it comes to scripts and such, I'm lost. I have a java script I bought that Im able to understand how to install due to good instructions, but what has been said here so far is over my head.

    Maybe I should just build these 3 pages (well 2 really, the 3rd is an affiliate offer) and then hire one of you guys to do this for me.

    Richard
    Signature

    Sig is having a cig.....

    {{ DiscussionBoard.errors[1533637].message }}
    • Profile picture of the author Tim Brownlaw
      Richard, here is the ebook on the subject.

      It's written as a tutorial and the solution is developed in it so it's teaching you some PHP at the same time plus a few other bits and pieces.

      Or you can skip that bit and just go straight to the solution, read the instructions and download the file from the link provided.

      This is provided to anyone willing to read it.

      It's Free (Ho Ho Ho), no signup required ...but I would apppreciate some feedback on it (hopefully some good!).
      Yes , it's probably riddled with bad grammer etc...

      http://www.lookingovermyshoulder.com...al-Linking.pdf

      Cheers
      Tim
      {{ DiscussionBoard.errors[1534354].message }}
      • Profile picture of the author Richard-Malcolm
        Thank you very much Tim. I will take a look right away.

        Happy holidays to you and your family.

        Richard

        Originally Posted by Tim Brownlaw View Post

        Richard, here is the ebook on the subject.

        It's written as a tutorial and the solution is developed in it so it's teaching you some PHP at the same time plus a few other bits and pieces.

        Or you can skip that bit and just go straight to the solution, read the instructions and download the file from the link provided.

        This is provided to anyone willing to read it.

        It's Free (Ho Ho Ho), no signup required ...but I would apppreciate some feedback on it (hopefully some good!).
        Yes , it's probably riddled with bad grammer etc...

        http://www.lookingovermyshoulder.com...al-Linking.pdf

        Cheers
        Tim
        Signature

        Sig is having a cig.....

        {{ DiscussionBoard.errors[1534431].message }}

Trending Topics