Current location: Hot Scripts Forums » Programming Languages » PHP » finding where a redirect goes


finding where a redirect goes

Reply
  #1 (permalink)  
Old 04-17-07, 06:53 AM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy finding where a redirect goes

Hi. I have been trying to find a way of getting the location of where a 'www_websitename_com/redirect?id=something'. I have found how to download a page using CURL but have no idea where to go from there, if that is even the right way about it

Thanks in advance
Jay
Reply With Quote
  #2 (permalink)  
Old 04-17-07, 07:04 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
If you have PHP 5, try this:

PHP Code:


$url 
'www.websitename.com/redirect?id=something';

foreach (
get_headers($url) AS $header)
{
      if (
preg_match('/Location:\s*(.+)/i'$header$location))
      {
           echo 
trim($location[1]);
           break;
      }

Reply With Quote
  #3 (permalink)  
Old 04-17-07, 07:18 AM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
thanks for the quick reply. i've tested it on my localhost, and it hasnt worked i think there might be an error there somewhere because i added an extra echo statement to see if it would just print a line of text, and it didnt show anything
Reply With Quote
  #4 (permalink)  
Old 04-17-07, 07:24 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
I just tested it too, and it worked for me. I used www.google.com as URL, and it echoed www.google.es for me.

Run this and see what you get:
PHP Code:

$url 'www.websitename.com/redirect?id=something';

echo 
'<pre>' print_r(get_headers($url), true) . '</pre>'
Reply With Quote
  #5 (permalink)  
Old 04-17-07, 07:28 AM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
using that, i managed to do the same, with google that is. i got it to show the redirect as .co.uk. however, when i tried it on a redirect link, i got this


Array
(
[0] => HTTP/1.1 200 OK
[1] => Connection: close
[2] => Date: Tue, 17 Apr 2007 12:27:19 GMT
[3] => Server: Microsoft-IIS/6.0
[4] => X-Powered-By: ASP.NET
[5] => Content-Length: 1280
[6] => Content-Type: text/html
[7] => Set-Cookie: ASPSESSIONIDAQCRSDSR=FCOLLBCCPAAELIHFDDMCDNDA; path=/
[8] => Cache-control: private
)
Reply With Quote
  #6 (permalink)  
Old 04-17-07, 07:41 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
They're probably using an HTML meta redirect then. Give this a try:

PHP Code:

$url 'www.websitename.com/redirect?id=something';

if (
preg_match('/<meta\s+http-equiv\s*=\s*["\']?refresh["\']?\s+content\s*=\s*["\']?[\s\d]*;URL\s*=\s*([^"\'>]+)/i'file_get_contents($url), $url))
{
    echo 
$url[1];

Reply With Quote
  #7 (permalink)  
Old 04-17-07, 07:49 AM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up

Thats done it. thankyou so much Nico
Reply With Quote
Reply

Bookmarks


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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
please help me with redirect page Hoangsts ASP 3 12-08-06 08:58 AM
Redirect Recent Visitors Within Past Day? battle Script Requests 0 08-06-05 06:09 AM
Redirect Script. RossC0 JavaScript 2 02-10-05 05:02 AM
Redirect previous 2 pages after login mcrob PHP 5 01-01-05 07:35 AM
Need help finding software solutions Hyperdelicious The Lounge 2 06-07-03 07:04 PM


All times are GMT -5. The time now is 06:01 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.