Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies


4:50 pm on Mar 4, 2012 (gmt 0)


I'm trying to check if a website has a piece of code on it. The code is below.


I want to see if that is in the source code. If it is it will echo yes if not it will echo no.

Thank you
4:53 pm on Mar 4, 2012 (gmt 0)

What will be the quickest and most reliable way of doing that to. Thank you
11:00 pm on Mar 4, 2012 (gmt 0)

WebmasterWorld Administrator brotherhood_of_lan is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

Do you need a method to fetch the page or a method to match the string?

strpos [php.net] is good for the comparison

PHP has support for cURL [php.net] and there are examples on that page.
4:06 am on Mar 5, 2012 (gmt 0)

I was wondering if you could put together a code to look for


What I have written/tried doesn't work.

Thank you
2:52 am on Mar 6, 2012 (gmt 0)

This is what I have so far

$ch = curl_init("http://www.example.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$text = curl_exec($ch);
$test = strpos($text, "<!-- BEGIN TEST CODE -->");
if ($test==false)
echo "yes";
echo "no";

I'm always getting a yes on any page even the one that has


what am I'm doing wrong?
3:23 am on Mar 6, 2012 (gmt 0)

i got it to work but it doesn't seem to work on certain domains. Thanks
2:38 pm on Mar 13, 2012 (gmt 0)

echo "Found";
else echo "not Found";

function checkSite($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$text = curl_exec($ch);
$test = strpos($text, "<!-- BEGIN TEST CODE -->");
if ($test === false)
return false;
else return true;

With strpos you should allways do a strict comparison ( === instead of == )

If the text would start with the text you are searching for, strpos will return 0 (since the search text starts at char 0)

if 0 == false returns TRUE
if 0 === false returns FALSE

This just might be why you script fails
On top of that, in your above script, the If Else logic is the wrong way around ;)

7:45 pm on Mar 14, 2012 (gmt 0)

Thank you

Featured Threads

Hot Threads This Week

Hot Threads This Month