[PHP] javascript alert opvangen externe pagina

Pagina: 1
Acties:

Onderwerpen


Acties:
  • 0 Henk 'm!

  • DenDries
  • Registratie: Januari 2006
  • Laatst online: 07:44
Hallo,

Met een klein curl scriptje wil ik een externe pagina ophalen en de eventuele javascript alert opvangen.
(bv. De pagina geeft een javascript alert "File not found" als het te downloaden bestand niet werd gevonden.)

code:
1
2
3
4
5
6
7
8
9
10
$Input = "http://rapidshare.com/files/31336324/N_Ba.rar"

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $Input); 
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)'); // IE6 
curl_setopt($ch, CURLOPT_HEADER, false); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_exec($ch);
curl_close($ch);


Kan iemand mij vertellen hoe ik het best zo'n externe javascript alert kan opvangen?

Acties:
  • 0 Henk 'm!

Verwijderd

Letterlijk uit de broncode van die pagina:

<script>alert("File not found.")</script>

Dit lijkt me redelijk duidelijk te vinden en op basis hiervan actie te ondernemen.

Acties:
  • 0 Henk 'm!

  • DenDries
  • Registratie: Januari 2006
  • Laatst online: 07:44
Probleem is dat ik niet goed weet hoe ik met curl precies de broncode van de pagina kan doorzoeken.

EDIT:
Heb een werkende oplossing gevonden:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $Input); 
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)'); // IE6 
curl_setopt($ch, CURLOPT_HEADER, false); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
$pagina = curl_exec($ch);
curl_close($ch);

if (ereg("<p><script>alert(\"File not found.\")</script>File not found.</p>", $pagina)) {
// Als het niet voorkomt, error geven
echo "File not found!";
} 
else 
{
echo "Bestand gevonden!";
}

[ Voor 70% gewijzigd door DenDries op 14-08-2007 22:16 ]