user3721008
user3721008

Reputation: 103

301 Moved Permanently PHP Laravel

Hi I'm trying to get data from anther site so I used

    $url = 'MY_URL' . $route . '/' . $id;
    $ch = curl_init($url);

    curl_setopt($ch, CURLOPT_HTTPHEADER, array('url: ACCESS_URL', 'token: TOKEN'));
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, $type);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    //curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
    $output = curl_exec($ch);
    curl_close($ch);
    return $output;

so I get 301 Moved Permanently output I works fine on local machine put after uploading I got that error ,any suggestions

Upvotes: 0

Views: 884

Answers (2)

user8034901
user8034901

Reputation:

You need to specifically tell cURL to follow redirection:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

Upvotes: 0

user3721008
user3721008

Reputation: 103

the problem with me was missing component curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

Upvotes: 2

Related Questions