Here is the deal. I have a requirement to monitor certain password-protected webpage for changes and play sound alarm when size of the page is different from what I know (i.e. it was modified). Here is the chunk of code that i've come up with.
<?php
$e = curl_init();
curl_setopt($e, CURLOPT_URL, 'http://example.com/Account/LogOn');
curl_setopt($e, CURLOPT_POST, 1);
curl_setopt($e, CURLOPT_POSTFIELDS, '[email protected]&Password=password');
curl_setopt($e, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($e, CURLOPT_REFERER, 'http://example.com');
curl_setopt($e, CURLOPT_RETURNTRANSFER, 1);
curl_exec($e);
$sizevalue = 2399;
do {
curl_setopt($e, CURLOPT_URL, 'http://example.com/panel.php');
$content = curl_exec($e);
$numberofchars = strlen($content);
sleep(15);
} while ($numberofchars = $sizevalue);
curl_close($e);
echo '
<audio controls="controls" autoplay="autoplay">
<source src="/path/to/your/audio.mp3" type="audio/mp3">
<source src="/path/to/your/audio.ogg" type="audio/ogg">
<embed src="/path/to/your/audio.mp3">
</audio>';
php?>
Problem 1. Correct me if I am wrong, but as I understand, instead of connecting server, posting username and password only once, leaving the connection alive and using that auth key from cookie.txt
for later actions it constantly sends the username and password to the login form for every turn of the cycle. How do I fix this?
Problem 2. I need the script to give me some temporary status because at the moment if certain condition is not met it basically turns into infinite loop and server hosting the script gives me timeout error.
Problem 3. What would be the simplest way to implement sound alarm? OGG file playback? Youtube redirection?