简体   繁体   中英

Curl redirection not working. What am I doing wrong?

I want to redirect a specific page from my .in domain to my .com domain using curl and at the same time change the HTTP Referer to something else (blank).

I am using the following code :

<?php 

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.example.com/random');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_REFERER, '');
curl_exec($ch);
/*$html=curl_exec($ch); - tried this, but does not work.*/
curl_close($ch);

?>

The URL for the above script would be something like : http://www.example.in/random.php Upon navigating to the above URL where the script resides, I expect the client to be redirect to http://www.example.com/random . All I get is a blank page, without any error or any other data and no redirection too.

On executing the script form Firefox, Chrome, Safari or Opera, doesn't work. Basically, something in the script is wrong and I can't figure out what. I don't know much about Curl and this script was essentially pulled off from the Web.

I could be wrong but isn't curl() for downloading files rather than redirection? I would use php to set the header to do a redirect.

header("Location: www.mysite.com");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM