I used this function(=login) to login to a remote website and save cookie as "cookie.txt".
But the same lines of code don't work when i upload it on EC2.
From the scratch, I installed php5 using:
$ sudo apt-get install php5-curl
$ sudo service apache2 restart
Then uploaded "index.php" AND "simple_html_dom.php" that looks like this:
<?php
include('simple_html_dom.php');
$userid = "MYID";
$password = "MYPASSWORD";
login("https://SOMEWEBSITE.COM", "id=".$userid."&pw=".$password);
//then I'd have "cookie.txt" in the same directory as "index.php"
$lines = file("cookie.txt");
echo count($lines); //should echo int above -1
for($n=0; $n < count($lines); $n++)
{
echo "output->".$lines[$n]."<br>";
}
//unlink("cookie.txt");
function login($url,$data){
$fp = fopen("cookie.txt", "w");
fclose($fp);
$login = curl_init();
curl_setopt($login, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($login, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($login, CURLOPT_TIMEOUT, 40000);
curl_setopt($login, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($login, CURLOPT_URL, $url);
curl_setopt($login, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($login, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($login, CURLOPT_POST, TRUE);
curl_setopt($login, CURLOPT_POSTFIELDS, $data);
ob_start();
return curl_exec($login);
ob_end_clean();
curl_close ($login);
unset($login);
}
?>
Is there something that ec2 doesn't allow to do from the methods above?
My guess is maybe EC2 doesn't allow to write files on it... but not sure how to solve this. Any answers?
Aucun commentaire:
Enregistrer un commentaire