0

Im trying to right my first php script.

Im trying to get the script to look at a defined site's source to see if a length of code is present.

Ive been given this by a friend but im not sure its working as I get this error, and it always says it can see the code even though I made up some bogus search.

Warning: Wrong parameter count for strpos() in /home/#####/public_html/#######/test.php on line 3
Found it!

<?php
$source = file_get_contents("http://######.com/");
if(strpos('<a href="http://www.jimmy.com/"/>') !== false)
 echo "Found it!";
else
 echo "Didn't find it!";
?>

Any ideas on how I can progress this futher to a few textboxes and a button?

Thanks

3
Contributors
7
Replies
8
Views
6 Years
Discussion Span
Last Post by BleepyE
0

I responded before looking at the code in depth. Let me look and I'll tell you more, I've already found three problems. :)

Edited by dietdew12z: n/a

0
$source = file_get_contents("http://######.com/");

You need to get the actual file if possible - but, it may default to the index.php, index.htm, main.php, main.htm, home.php, home.htm (or the html equivalents).

In addition your host may disable your ability to access cross-domain files in this manner (as a safety precaution).

Your conditional may work, but I advise using braces, { and }.

The strpos needs a haystack and needle, so you need to place $source into the strpos:

if(strpos($source,'<a href="http://www.jimmy.com/"/>') !== false){
0

Okay. This works.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Page title</title>
</head>
<body>
<?php
$source = file_get_contents("http://placelogo.t35.com/index.php");
if(strpos($source,"function changeup()")!=false) {
 $begin=strpos($source,'function changeup()');
 $end=strpos($source,'</script>');
 $leng=$end-$begin;
 $result=nl2br(substr($source,$begin,$leng));
 echo "$begin, $end, $leng:<br />$result";
 }
else {
 echo "Didn't find it!";
 }
?>


</body>
</html>

Issues:

1. You need to specify the file you want to open, www.domain.com/ won't work.
2. I suspect the !== is what's causing your false positives, changing it to != seems
work much better.
3. strpos function needs two parameters. haystack, needle

That project looks like something a person could have a lot of fun with.

David

0

Now I'm curious as to why it isn't working when I put in the <title> tags or the <body> tags as a search. It returns the position numbers, but no text.

Does file_get_contents not pull the entire source file?

Edited by dietdew12z: n/a

0

strpos() only returns a number (char pos) if present. The $source contains the text. You need to use something like substr() to extract a specific piece of file. Either that or use regex.

0

Thanks, everyone.

<?php
$source = file_get_contents("http://bleepyevans.com/");
if(strpos($source,'bleepyevans') !== false)
{
echo "Present";
}
else
{
echo "Not Present";
}
?>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.