AlexB
AlexB

Reputation: 2174

URL redirect with urlid string creates request in a way that will never complete

I am stack in did!!!

I have a simple URL redirect script that I use to redirect visitor to the widget download page using again simple urlid string

http://www.example.com/get.php?urlid=blue_widget

rest is as usual, when request is send to get.php which returns the url of the download landing page.

Now the problem:

everything works fine when correct urlid is sent or if it was sent empty then my get.php redirects the visitor to my main index page. The problem happens when unknown (none existent) urlid is sent, than browser returns the following

The page isn't redirecting properly Firefox has detected that the server is redirecting the request for this address in a way that will never complete. This problem can sometimes be caused by disabling or refusing to acceptcookies.

Here is content of my get.php file

<?php
$urlid = $_GET['urlid']
if ($urlid == "") {$link = "http://www.example.com/";}
if ($urlid == "blue_widget") {$link = "http://www.example.com/download.php?fileid=blue_widget.doc";}
header ("Location: $link");
exit();
?>

Please help

Upvotes: 1

Views: 433

Answers (3)

bastienbot
bastienbot

Reputation: 123

You can also check if the file exists by doing so :

if (file_exists(basename($_GET['urlid']).".doc"))
{$link = "http://www.example.com/download.php?fileid=".$_GET['urlid'].".doc";}

Upvotes: 0

vcampitelli
vcampitelli

Reputation: 3252

You could do something like this:

<?php
if (isset($_GET['urlid'])) {
    switch ($_GET['urlid']) {
        case 'blue_widget':
            $link = 'http://www.example.com/download.php?fileid=blue_widget.doc';
            break;
        case 'second_widget':
            $link = 'http://www.example.com/download.php?fileid=second_widget.doc';
            break;
        case 'blabla':
            $link = 'http://www.example.com/download.php?fileid=blabla.doc';
            break;
        default:
            $link = 'http://www.example.com/';
    }
} else
    $link = 'http://www.example.com/';
header("Location: $link");
exit();

I hope it helps you! =)

Upvotes: 1

etoipi
etoipi

Reputation: 57

Use the PHP isset function http://php.net/manual/en/function.isset.php to see if $_GET['urlid'] is set.

Upvotes: 0

Related Questions