Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 12th, 2006, 1:04 PM   #1
drumltd
Newbie
 
Join Date: Aug 2005
Posts: 19
Rep Power: 0 drumltd is on a distinguished road
Final Destination.

Anybody know how give a URL such as

http://www.webhostdir.com/banners/banman.asp?ZoneID=9&Task=Click&Mode=HTML&SiteID=1&PageID=

How one can find the final destination which in this case is

http://www.webintellects.com/

Bearing in mind there are probably lots of ways that a link could be redirected to the final site.
drumltd is offline   Reply With Quote
Old Nov 12th, 2006, 1:34 PM   #2
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
One would have to open up a HTTP connection to the URL, and then get the value of the redirect. PHP has some HTTP handling functions, and it's sometimes compiled with CURL, which might be easier. I suspect it would just be a case of parsing out the right header, or having a library follow the link and see where it goes.
Arevos is offline   Reply With Quote
Old Dec 13th, 2006, 2:27 AM   #3
headzoo
Newbie
 
Join Date: Oct 2006
Posts: 16
Rep Power: 0 headzoo is on a distinguished road
This might help you a little bit. It's a sloppy function I created a while back that grabs the contents of a document using HTTP via sockets. It follows 301 and 302 redirects. I've tweaked it a bit for your situation.

function get_http_document($url, &$headers = null, $port = 80, $timeout = 8) {
	global $paths;
	$paths[] = $url;
	$pURL = parse_url($url);
	
	if (empty($pURL['host'])) {
		return false;
	}

	$remotePath = 		(isset($pURL['path'])) ? $pURL['path'] : '/';
	$remoteDocument = 	(empty($pURL['query'])) ? $remotePath : $remotePath . '?' . $pURL['query'];
	
	if (!$fp = @fsockopen($pURL['host'], $port, $errno, $errstr, $timeout)) {
		return false;
	}
	
	$out = 	"GET $remoteDocument HTTP/1.0\r\n";	
	$out .= "Host: {$pURL['host']}\r\n";
	$out .=  "Connection: Close\r\n\r\n";
	fwrite($fp, $out);
	unset($out);
	
	$received = '';
	while (!feof($fp)) {
		$received .= fread($fp, 128);
	}
	fclose($fp);

	// Seperate the headers from the content
	$parts = explode("\r\n\r\n", $received, 2);
	$headers = $parts[0];
	$content = $parts[1];
	unset($parts);
	

	$headerParts = explode("\r\n", $headers);
	if (!preg_match('~HTTP/1\.\d ([\d]+)~i', $headerParts[0], $matches)) {
		return false;
	}
	$statusCode = $matches[1];
	
	if ($statusCode == 200) {
		return $content;
	} else if ($statusCode != 301 && $statusCode != 302) {
		return false;
	}
	
	if (!preg_match('~^Location:(.*)$~im', $headers, $matches)) {
		return false;
	}
	$newLocation = trim($matches[1]);
	return get_http_document($newLocation, $headers, $port, $timeout);
}

Be aware this uses the global variable $paths inside the function. That's just bad coding. But you would use the function like this:

$paths = array();
$content = get_http_document('http://www.webhostdir.com/banners/banman.asp');
print_r($paths);

The contents of the remote document will be in $content. Every website that was visited to get to the final destination will be in the $paths array. That array will look like this:

Array
(
    [0] => http://www.webhostdir.com/banners/banman.asp?ZoneID=9&Task=Click&Mode=HTML&SiteID=1&PageID=
    [1] => http://www.webintellects.com
)

That shows you that the first site visited was webhostdir.com. Then it went to webintellects.com. And so on.

- Sean
headzoo is offline   Reply With Quote
Old Dec 13th, 2006, 11:59 AM   #4
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
Seems to me this could be consitered hacking.
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Instant Messaging System Final Year Project bondito Java 20 Oct 28th, 2007 11:08 PM
Simple java problem Mixmaster Java 3 Oct 3rd, 2006 2:57 PM
declaring a variable final b1g4L C++ 5 Jan 19th, 2006 11:41 AM
Final Year Dissitation Berto Coder's Corner Lounge 4 Jun 14th, 2005 6:36 AM
University Final Year Project nez Project Ideas 3 May 23rd, 2005 8:59 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:41 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC