Salve, sono nuovo nel forum e vorrei sapere com'è possibile eseguire l'autenticazione su un sito attraverso il curl ed estrarre il contenuto html ( Per precisione il value di un input hidden).
Il problema è sorto in quanto il sito in questione effettua l'autenticazione ma subito dopo si indirizza su un'altra pagina e sembrerebbe che il curl appunto non funzionasse.


Questo è lo script utilizzato, le variabili definite le prende da un config.php:
Codice PHP:
<?

// ---------------------------------------------------------------------
// This file uses CURL to logon to Geovision HTTP web server and then
// Parse the HTML using the PHP XML parser, return the GUID
//
// Written and Copyrighted by: Mythos and Rini
// Created on: 2010-09-12
//
// Required: Geovision version 8.2 
//           PHP with CURL and GD library installed
//
// Notes: Change the Server name, Username, Password in config.php
// ---------------------------------------------------------------------


$url 'http://' GN_GEOVISION_CAMERA '/webcam_login'
$ch curl_init($url);

//
// In Geovision HTML form, it takes 2 HTML form elements "id" and "pwd"
// Also, ImageType = 2 - JPG
// 

 
curl_setopt ($chCURLOPT_POST1);
 
curl_setopt ($chCURLOPT_RETURNTRANSFER1); // return as string instead of showing to screen
 
curl_setopt ($chCURLOPT_POSTFIELDS"id=" GN_GEOVISION_USER ."&pwd=" GN_GEOVISION_PASSWORD."&ImageType=2");

 
$output curl_exec($ch);


//Create a new DOM document
$dom = new DOMDocument;
 
//Parse the HTML. The @ is used to suppress any parsing errors
//that will be thrown if the $html string isn't valid XHTML.
@$dom->loadHTML($output);
 
//Get all links. You could also use any other tag name here,
//like 'img' or 'table', to extract other tags.
$nodes $dom->getElementsByTagName('title');
 

$nodeListLength $nodes->length// this value will also change

$node $nodes->item(0);

// Since there should be ONLY one element returns, that's the GUID
$geo_guid $node->nodeValue;


// Close handle
curl_close($ch);

?>