1

In my php page, I want to call another URL for the user depending on other values. My code will now go to the new page, but I need to click on the message

You are being redirected. // //

Then it will go to the proper page. How do I call the new page and not get this message ? Here is my code so far.

    <?php

    require_once 'libs/Mobile_Detect.php';
    $detect = new Mobile_Detect;

    if ($detect->isMobile() )
        { 
        $url = $_GET["link2"];
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        $result = curl_exec($ch);
        curl_close($ch);

    }
    else{
        // "desktop";
        ?> <h1><?php echo $_GET["title"]; ?></h1>
        <iframe src='<?php echo $_GET["link"]; ?>' frameborder="1" 
             width="1311px" height="800px"></iframe>
      <?php
    }
    ?>
rtemen
  • 137
  • 4
  • 17

1 Answers1

2

The first thing to try is curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); which corresponds to the command line parameter curl -L.

Versions of cURL prior to 7.19.4, which were included with old, no longer supported versions of PHP, do not correctly check for redirection from HTTP or HTTPS URI to a local file. This could be used to circumvent open_basedir restrictions, as mario pointed out in another answer. Thus for these versions of cURL, if safe_mode or open_basedir is set, PHP raises an error if a program attempts to turn on CURLOPT_FOLLOWLOCATION. This was fixed in PHP 5.5.3, and the fix remains in all supported PHP versions.

If turning on CURLOPT_FOLLOWLOCATION does not resolve the redirection, the site may not be using 301/302 redirection at all but instead use JavaScript redirection or no redirection as a means to deter abuse by automated processes. A site doing this expects the user to follow the link through manual navigation (clicking with a mouse, tapping with a touch screen, or tabbing and pressing Enter). For this, you'd have to parse the HTML to read the link's target. First load the HTML into a DOMDocument and then look for <a> elements with a promising href attribute.

Damian Yerrick
  • 4,602
  • 2
  • 26
  • 64