Grow your CSS skills. Land your dream job.

[Solved] Redirect Pages ?

  • # September 4, 2009 at 7:19 pm

    Hello,

    I’m new to PHP. I was searching for a solution on the internet already but didn’t find anything for my problem.
    I have a small list with links/bookmarks to external websites. I don’t wan to link them directly. I want to create a redirect page.

    A) My links are shown like that:


    <li>http://www.mydomain.com/redirect.php?URL=http://www.externalsite.com</li&gt;
    <li>http://www.mydomain.com/redirect.php?URL=http://www.externalsite2.com</li&gt;
    <li>http://www.mydomain.com/redirect.php?URL=http://www.externalsite3.com</li&gt;
    etc.

    B) My redirect.php file contains:


    <?php
        if (isset ($_GET) && preg_match (‘/^http://.+/i’, $_GET))
            header ("Location: " . $_GET);
        else
            // Alert if redirection failed.
            echo "Redirection failed!";
    ?>

    C) If I click on the link shown above the following error message appears:


    Parse error: syntax error, unexpected T_STRING in /path_to_my_domain/redirect.php on line 3

    I already checked the syntax but didn’t find any errors which causes the message from above.

    Any suggestions to solve the problem? Or do I have to choose another solution for my redirect problem?

    Thanks a lot,
    Michael

    # September 6, 2009 at 10:41 pm

    The superglobal variable $_GET is only used to collect information from a form that is sent with method="get"

    So if you you just a URL inside <li> tags and then attempt to grab that, it won’t work.

    # September 6, 2009 at 11:05 pm

    Maybe try something kind of like this…

    Your HTML form:

    Code:
    < !DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">




    Where would you like to go?


    Your redirect.php page

    Code:
    < ?php

    if(isset($_GET['url'])) {
    header("Location: http://".$_GET['url']);
    }
    else {
    print 'Error redirecting!';
    }

    ?>

    # September 7, 2009 at 1:55 am

    Thanks a lot for reply!

    The problem I do have is, I have to put the links in a list (<li>). I can’t collect them in a pulldown menu.
    Is there another solution for redirecting pages?

    M.

    # September 7, 2009 at 4:02 pm

    I found a solution…

    1. Create a page redirect.php:
    <?php
    $url = $_GET;
    header("Location: $url");
    ?>

    2. Create a robots.txt file and write:
    Disallow: /redirect.php?*

    3.
    In the page where you list all of the links you, write the following code:
    <li>http://www.yourownpage.com/redirect.php?url=http://www.externallink1.com</li&gt;
    <li>http://www.yourownpage.com/redirect.php?url=http://www.externallink2.com</li&gt;
    <li>http://www.yourownpage.com/redirect.php?url=http://www.externallink3.com</li&gt;

    4. That’s all!

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".