Hello,
I am trying to parse a PHP page for a specific String, and if it exists stop refreshing. If it does not exist, refresh X seconds. Anything like this possible in PHP? The page I am parsing is located on another server, so I would probably Include that into this page first. Any ideas on how to get started?
Thanks
Refresh Page until...
Moderator: General Moderators
Does this look somewhat right? One thing I couldn't figure out was how to show the webpage inside the IF statement? Is echo $tmp correct? Don't have PHP installed on this computer just yet, so will test it soon.
Code: Select all
<?php
$ch = curl_init("http://www.example.com/");
$fp = fopen("example_homepage.txt", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
$tmp = curl_exec($ch);
curl_close($ch);
if (substr_count("Word", $tmp) => 2)
{
// Show Webpage
echo $tmp;
$fclose($fp);
}
else
{
// Refresh Page
$fclose($fp);
header( 'refresh: 600; url=refresh.php' );
}
?>I got almost everything working, only problem is the site sets a cookie on the first time you visit the page. So I tried to use curl's cookie functions to emulate this sending of the cookie back to the server but isn't working. Not sure if I am even using it right. Here is the code, thanks for your time.
Code: Select all
<?php
$user_agent = "Mozilla/4.0";
$ch = curl_init("http://www.notsureyet.com/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, "c:\cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "c:\cookie.txt");
curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
// curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
$tmp = curl_exec($ch);
curl_close($ch);
//echo $tmp;
if (substr_count($tmp, "findme") == 1)
{
// Show Webpage
echo $tmp;
}
else
{
// Refresh Page
header( 'refresh: 1000; url=refresh.php' );
}
?>