Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP code to detect if a url has a redirect loop
Old 06-10-2011, 10:39 AM PHP code to detect if a url has a redirect loop
Average Talker

Posts: 25
Name: Reuven Gloriss
Location: NYC
Trades: 0
Hi,
I have a php script that open pages and check the html for specific backlinks.
I have a problem when a url has a redirect loop, my program does not work.

Any suggestions for identifying if a web address has a redirect loop?

Thanks
__________________
A Computer is like your body, protect it, use it smartly, add new features - and it will perform better.

Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
ruven is offline
Reply With Quote
View Public Profile Visit ruven's homepage!
 
 
Register now for full access!
Old 06-10-2011, 10:43 AM Re: PHP code to detect if a url has a redirect loop
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Can you clarify? Is your script following links? So if Page A links to Page B which links back to Page A your script will be stuck in a loop?

If that's the case you just need to keep track of which URLs you've already visited and ignore any additional links to that URL.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 06-10-2011, 11:16 AM Re: PHP code to detect if a url has a redirect loop
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Ideally you should be using CURL for this..
If so, You can use the CURLOPT_MAXREDIRS function to stop it.
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 06-10-2011, 11:25 AM Re: PHP code to detect if a url has a redirect loop
Average Talker

Posts: 25
Name: Reuven Gloriss
Location: NYC
Trades: 0
NO it is not following links it is opening a webage like this:
PHP Code:
$field['url_get'] = @fsockopen($field['hostname_short'], $field['hostname_port']); # Connect to domain
            
fputs($field['url_get'], "GET ".$field['hostname_page']." HTTP/1.0\r\nHost: ".$field['hostname_short']."\r\n\r\n"); # Request page from domain

            
$field['url_content'] = "";

            while(!
feof($field['url_get'])) { # Get data by line and store

                
$field['url_content'] .= fgets($field['url_get'], 10240);

            } 
And then looking for specific text (links)
Thanks
__________________
A Computer is like your body, protect it, use it smartly, add new features - and it will perform better.

Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
ruven is offline
Reply With Quote
View Public Profile Visit ruven's homepage!
 
Old 06-10-2011, 11:41 AM Re: PHP code to detect if a url has a redirect loop
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Using cURL you should be able to read the HTTPD headers and determine if the Location: header is set.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 06-10-2011, 12:04 PM Re: PHP code to detect if a url has a redirect loop
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Or check the response code for 301, 302 or 307.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to PHP code to detect if a url has a redirect loop
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.23893 seconds with 12 queries