Page 1 of 1

Code generates good and bad output...

Posted: Wed May 26, 2010 11:54 am
by miniramen
hello,

I used a file to go on numerous websites in order to check if a code is inside all of them.
I managed to go on all these websites, and by using curl, getting their contents.
I used foreach in order to ask the script to do an action for each of the websites.
Then, I used the function strpos in order to check it the code exists or not inside the script.

Unfortunately, the code somehow is unable to find the code, even though I know that it's inside the script.
Actually, thing is that it outputs good and bad outputs. Here's the code.

Code: Select all

<?php
set_time_limit(0);
$file_open = fopen("RedirectIds.csv","r");
$site_array = array();

while (!feof($file_open)) 
{
    $line_of_text = fgetcsv($file_open, 1024);
    $redirectId = $line_of_text[0];
    if(is_numeric($line_of_text[0]))
    $site_array["$redirectId"] = "http://**********/" . $redirectId . "." . "html";    //<<< the website is private matter, sorry.
}
	


                        
            
foreach ($site_array as $redirectId => $site)
{     
                   
    $curl = curl_init(); 
    curl_setopt($curl, CURLOPT_URL, $site);   	
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, True);	
    $site_content = curl_exec($curl);
	curl_close($curl);

echo strpos(htmlentities($site_content), $redirectId) . ",    ";
echo $redirectId;
 
    if (strpos(htmlentities($site_content), $redirectId) != False)
        echo $site . ", " . "true" . "<br />" ;
    else
        echo $site . ", " . "false" . "<br />" ;

}     
  
 fclose($file_open);                  
?>
Plz enlighten me, I've been working on this for hours, not getting what is wrong at all.

Re: Code generates good and bad output...

Posted: Wed May 26, 2010 4:01 pm
by requinix
Inside the script or inside the HTML output?

Re: Code generates good and bad output...

Posted: Thu May 27, 2010 12:05 am
by miniramen
Hmm? I'm not entirely sure what you mean by that, but let me clarify a little bit more.

Output is when my script was able to find successfully the code that is inside the HTML contents of specific sites.
Supposedly, I made the script so it's supposed to find the code and STRPOS should tell me a position, not a false value.

So I was crawling 5 sites for different codes, and I know that these different codes are inside these 5 sites.
Using STRPOS, I should get a value.

Problem is that out of these 5 sites, there's only 2 sites that the script was able to find the code from.
So that means the script works 2/5 times....why?

I try testing, using various php functions...just not happening.