csharp newbie
csharp newbie

Reputation: 638

curl request redirects me to localhost page

I am new to curl and php in general, at the moment I'm trying to get the page source, so I can work with it later.

This is my entire code

$ch = curl_init();
$id="3005752358";
$url = "https://www.opendota.com/matches/".$id;
$header[] = "Accept: application/json";
$header[] = "Accept-Encoding: gzip";
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt( $ch, CURLOPT_HTTPHEADER, $header );
curl_setopt($ch,CURLOPT_ENCODING , "gzip");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );

$response = curl_exec ($ch);
 if ($response === false) 
    $response = curl_error($ch);
echo stripslashes($response);
curl_close($ch);
echo "asd";

For some reason when I open the page, it redirects me on this url: localhost

There's a similar question from 4 years ago, but it looks like the subject is completely different ( PHP cURL redirects to localhost )

Upvotes: 2

Views: 877

Answers (1)

Sherif
Sherif

Reputation: 11943

Because the response from this URL contains javascript that redirects:

<script>
  window.sessionStorage.redirect = window.location.href;
</script>

As well as a meta tag that refreshes the page, pointing back to the site root.

<meta http-equiv="refresh" content="0;URL='/'"></meta>

Try looking at the output in your console, next time since debugging this sort of thing in the browser is only bound to lead to obvious confusion.

Upvotes: 1

Related Questions