Beste,

Ik heb het volgende script:
<?php
//hier komt de url van de ontvanger
$ch = curl_init("https://www.hierishetinlogformulier.nl/";);

//checkt of de SSL certificaat geldig is
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

//volgende blokje code zorgt dat de ontvangende server de data krijgt als post
curl_setopt($ch, CURLOPT_POST, 1);
//van de volgende regel code, kan ontvanger uitlezen als $_POST['user'] en pass als $_POST['pass']
//dat kan je gebruiken om zeg maar een authorized user te zijn.
$klant_nummer = *;
$gebruikersnaam = *;
$wachtwoord = '*';
curl_setopt($ch, CURLOPT_POSTFIELDS, "UsernameOU=1505197&UsernameCN=001&Password=temp3");

//dit gebruik je om de data terug te krijgen
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

//hier komt de output van de script
$output = curl_exec($ch);

//dit is de evt. error
$error = curl_errno($ch);

//naja dit is duidelijk
curl_close($ch);

if ($error != 0) {
echo $error;
}
else {
echo 'Output: '.$output;
}
?>

Ik kryg als output dat ik moet inloggen, wat doe ik verkeerd?
Kheb nu de volgende code:
<?
#### INLOG MAKEN
$action="www.sitevanformcheck.nl" ;
$ch = curl_init($action);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_HEADER, true );
curl_setopt($ch, CURLOPT_POST, true );
curl_setopt($ch, CURLOPT_POSTFIELDS, "Username=gebruikersnaam&Password=wachtwoord&Redirect=loggedIn.jsp") ;
curl_setopt($ch, CURLOPT_REFERER, "www.sitevanformulier.nl" );
#curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT , 'Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.1.1) Gecko/20090715 Firefox/3.5.1');
$r=curl_exec($ch);

preg_match_all("|Set-Cookie: (.*)|i", $r, $cookie);

print_r($cookie);

##### OK IETS UITLEZEN EEN PAGINA

$ch = curl_init(www.hiermoetuitgelezenworden.nl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_HEADER, true );

curl_setopt($ch, CURLOPT_COOKIE, $cookie[0] );
curl_setopt($ch, CURLOPT_COOKIE, $cookie[1] );

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_REFERER, $action );
curl_setopt($ch, CURLOPT_USERAGENT , 'Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.1.1) Gecko/20090715 Firefox/3.5.1');
$r=curl_exec($ch);
$r = nl2br($r);

print $r;
?>

En de errors:
Notice: Array to string conversion in /Users/joostvandermeijden/mamp_sites/sites/sanizo.nl/check_prices.php on line 25
Notice: Array to string conversion in /Users/joostvandermeijden/mamp_sites/sites/sanizo.nl/check_prices.php on line 26

Wat gaat er fout? Met PHP4 werkt 't wel.

Mvg, Hans.
Wat zijn in bovenstaand stukje code de regels die in jouw script overeenkomen met regel 25 en 26?
Zal toch met die cookie te maken hebben Blanche :/
Ja, dat is mijn vermoeden ook. Het was een stille hint waarmee de TS wellicht zag waar het script de fout in ging.

Maar goed, als het om regel 25 en 26 uit bovenstaand stukje code gaat, zou je eens moeten kijken wat $cookie[0] en $cookie[1] voor inhoud hebben:

<?php
var_dump($cookie[0]);
?>
<?php
print_r($cookie);
echo '<br/ ><br />Cookie0: '.var_dump($cookie[0]);
echo '<br/ >Cookie1: '.var_dump($cookie[1]);
?>

Array ( [0] => Array ( [0] => Set-Cookie: JSESSIONID=****; Path=/servlet; Secure ) [1] => Array ( [0] => JSESSIONID=****; Path=/servlet; Secure ) ) array(1) { [0]=> string(79) "Set-Cookie: JSESSIONID=******; Path=/servlet; Secure " }

Cookie0: array(1) { [0]=> string(67) "JSESSIONID=*****; Path=/servlet; Secure " }
Cookie1:
Voila, dat is je probleem: $cookie[0] is zelf ook nog een array. In curl_setopt() wordt daar echter een string verwacht. Kortom, gebruik $cookie[0][0].
<?php
print_r($cookie);
echo '<br /><br />Cookie: '.$cookie[0][0];
// ....
curl_setopt($ch, CURLOPT_COOKIE, $cookie[0][0]);
// ....
$error = curl_error($ch);
$r=curl_exec($ch);
$r = nl2br($r);

if ($error != 0) {
echo '<br />Error: '.$error;
}
else {
echo $r;
}
?>

Ik heb helaas geen output, maar ook geen error. Iemand enig idee wat er fout gaat?


Edit:
Output van $cookie[0][0] = Set-Cookie: JSESSIONID=*****; Path=/servlet; Secure
Dump eens wat variabelen met behulp van [php]var_dump[/php]() en controleer daarmee of de inhoud wel klopt...

Reageren