Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

<?php
error_reporting(-1);
$config = array
(
    "siteURL"        => "http://domain.com",
    "loginCheck"     => "checkuser.php",
    "userAgent"      => "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16"
);

$postFields = "username=user&password=pass&submit= Login ";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $config['siteURL'] . $config['loginCheck']);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERAGENT, config['userAgent']);
curl_setopt($ch, CURLOPT_REFERER, config['siteURL']);

$content = curl_exec($ch);
curl_close($ch);

echo $content;

?>

I expect this to be echoing the result of the curl, but its not. am I doing anything wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
498 views
Welcome To Ask or Share your Answers For Others

1 Answer

It does, if you set a complete URL with a '/' at the end (fix two other typos):

error_reporting(-1);
$config = array
(
    "siteURL"        => "http://www.apple.com/",
    "loginCheck"     => "checkuser.php",
    "userAgent"      => "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16"
);

$postFields = "username=user&password=pass&submit= Login ";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $config['siteURL'] . $config['loginCheck']);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $config['userAgent']);
curl_setopt($ch, CURLOPT_REFERER, $config['siteURL']);

$content = curl_exec($ch);
curl_close($ch);

echo $content;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...