Pythondev Posted June 23, 2006 Share Posted June 23, 2006 Ok,What I have is this... I have a link which when clicks redirects you to another page... For example lets say this link is example.com/website/hello/329472 and this redirects to domain.com/page.htmlWhat I want to do is have a script where you type in the original url, in this case example.com/website/hello/329472 and it finds out what the page that it redirects to is...This needs to be done with no user input though apart from typing in the original URL. and if possible id like it so it doesnt show the website loading or anything...How can I do this?Thanks Quote Link to comment https://forums.phpfreaks.com/topic/12767-get-url-after-its-been-redirected/ Share on other sites More sharing options...
shoz Posted June 23, 2006 Share Posted June 23, 2006 Note that the e in "curl_exec" is removed from the code below to allow the post to be accepted on the board.[code]<?php$ch = curl_init();$url = 'http://example.com/website/hello/329472';curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_NOBODY, 1);curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);$r = curl_xec($ch);$url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);curl_close ($ch);print $url;?>[/code][url=http://php.net/curl]http://php.net/curl[/url]If curl isn't installed you can do this manually using [url=http://ttp://www.php.net/fsockopen]fsockopen[/url] and complimentary functions by doing the HTTP request manually. There should be examples in the "User Contributed Notes" that you can look at.You should also be able to use [url=http://www.php.net]fopen[/url] and [url=http://www.php.net/stream_get_meta_data]stream_get_meta_data[/url] to follow the redirects.If this "redirect" is done internally by Apache using ModRewrite I don't know how you'd get the url. Perhaps by parsing a log file with ModRewrite debug info. Quote Link to comment https://forums.phpfreaks.com/topic/12767-get-url-after-its-been-redirected/#findComment-48940 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.