joshj Posted June 25, 2008 Share Posted June 25, 2008 Hello, I had a redirect script working, but lately it has stopped and the page in the browser just has: "The URL has moved here." I'm not sure where this is coming from or why it isn't redirecting. PHP Code: $ch = curl_init(); $fp = fopen("redirecting.html", "w"); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_REFERER, $referer); #curl_setopt($ch, CURLOPT_FILE, $fp); curl_exec ($ch); curl_close($ch); fclose($fp); I added the line curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); and it redirects fine but the original url is kept in the address bar which is not desirable. It would be great if someone knew how to fix this. Josh Link to comment https://forums.phpfreaks.com/topic/111929-curl-redirect-problem-url-has-moved-here/ Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 what do you meant he original url is kept in the address bar? curl is for retrieving webpages, not redirecting. are you trying to redirect someone so when they visit: http://yourhost.com/oldpage.php it forwards them to: http://yourhost.com/newpage.php ?????????? if so, the code for that is: <?php header('Location: newpage.php'); exit; ?> Link to comment https://forums.phpfreaks.com/topic/111929-curl-redirect-problem-url-has-moved-here/#findComment-574563 Share on other sites More sharing options...
joshj Posted June 26, 2008 Author Share Posted June 26, 2008 Someone clicks the link: http://yourhost.com/oldpage.php And they arrive at http://somewhere.com curl_setopt($ch, CURLOPT_REFERER, $referer); This sets the referrer value which is what I need. Can I set the referrer value with <?php header('Location: newpage.php'); exit; ?> ? Link to comment https://forums.phpfreaks.com/topic/111929-curl-redirect-problem-url-has-moved-here/#findComment-574596 Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 The referrer needs to be oldpage.php? Well, the curl method isn't actually sending them to that page. PHP fetches the page for them and displays the contents of it. If you want them to be forwarded with the right referrer, i think you have to use a JavaScript forward. Why does somewhere.com need the referrer set? Link to comment https://forums.phpfreaks.com/topic/111929-curl-redirect-problem-url-has-moved-here/#findComment-574604 Share on other sites More sharing options...
joshj Posted June 26, 2008 Author Share Posted June 26, 2008 I am just wanting a redirect with a masked referrer. Originally this code was working but now clicking on the link I am getting the message "The URL has moved here." with no redirect. Josh Link to comment https://forums.phpfreaks.com/topic/111929-curl-redirect-problem-url-has-moved-here/#findComment-574639 Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 That means that the URL stored in $url is sending that to you. Put that URL in your browser and see what it says. Link to comment https://forums.phpfreaks.com/topic/111929-curl-redirect-problem-url-has-moved-here/#findComment-574697 Share on other sites More sharing options...
joshj Posted June 26, 2008 Author Share Posted June 26, 2008 The $url stored in my php script is different from the one that I get in the browser message (the url has moved here). I think the remote site is blocking my redirect some how. Not sure why or how, but I can do a simple java redirect or php header('Location: http://xxx..."); and using the line "curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);" works too. Not sure what the difference is. Link to comment https://forums.phpfreaks.com/topic/111929-curl-redirect-problem-url-has-moved-here/#findComment-574755 Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 Can you share what the value of $url and $referer is? If I understand everything right, the page located at $url has moved to a new place, so you need to use the FOLLOWLOCATION or update the value of $url. ...and let me try to explain this further.... CURL is not a redirect. The client's browser is fetching your PHP page that has the CURL code in it. Your PHP code is then fetching the contents of $url and displaying it to the client's browser. The client's browser never makes it's own request to $url page. Therefore, the value in the location bar SHOULDN'T say the value of $url because their browser is in deed looking at your PHP script, not the $url page fetched in the background. If you want the client's browser to actually go to that page, you can use a PHP's header(), HTML's meta-redirect, or JavaScript's window.location.href. But, all will have a referrer of the last page the client's browser was at. You cannot control what the user's referrer is. Does that make more sense? Link to comment https://forums.phpfreaks.com/topic/111929-curl-redirect-problem-url-has-moved-here/#findComment-574997 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.