pink Posted November 3, 2006 Share Posted November 3, 2006 Hello.I was wondering if anyone knows how to grab an URL that is re-directed many times. Forexample, if I create a pageA that have header("Location pageB.php"), and page B redirect to page C.My goal is to get URL of page C from page A. You probably have experiences that URL that you've typed in and final destination URL are different. Often happens for JSP or .NET site. I am looking for way to get the final URL (page C) without hard coding it from initial URL (page A). I've tried with <a href="http://us3.php.net/manual/en/function.fread.php">fread</a> but it grabs HTML of inital page (page A). Has anyone tried this? If so, were you successful? What was your solutions?Thank you!!!!! Link to comment https://forums.phpfreaks.com/topic/26061-grabing-final-url-of-redirect/ Share on other sites More sharing options...
pink Posted November 3, 2006 Author Share Posted November 3, 2006 Any suggestions will be apperciated even you may haven't yet tried it! I am looking for ideas that may lead me to solutions. Thank you!!!!!!! Link to comment https://forums.phpfreaks.com/topic/26061-grabing-final-url-of-redirect/#findComment-119210 Share on other sites More sharing options...
shoz Posted November 3, 2006 Share Posted November 3, 2006 If [url=http://www.php.net/curl_exec]curl[/url] is installed you can use the following to retrieve the page.[code]<?php$url = 'http://www.com';$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);$r = curl_exec($ch);?>[/code]You should also be able to use file_get_contents to retrieve the final page. Link to comment https://forums.phpfreaks.com/topic/26061-grabing-final-url-of-redirect/#findComment-119236 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.