简体   繁体   中英

https login page with curl

I can't get php curl to work. I need to log in to a page and then get the source code for a page right after login.

<?php

//user login information
$username = "";
$password = "";
$submit = "Login";
//server link and variables
$url ="https://orapp2.hunter.cuny.edu/sims/cls.MySchedule.login";
$nameField ="p_login_name";
$passField ="p_passwd";
$subField ="Login";

$cookie_file = "/tmp/cookie.txt";

$page = curl_init($url);

curl_setopt($page , CURLOPT_POST, 1);
$postData = $nameField."=".$username."&".$passField."=".$password."&".$subField."=".$submit;
curl_setopt($page, CURLOPT_POSTFIELDS, $postData);
curl_setopt($page, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($page, CURLOPT_COOKIEJAR, $cookie_file);

$out = curl_exec($page);
echo $out;
curl_close($page);    

?>

Take a look here :

http://www.codercaste.com/2009/12/15/use-curl-with-php-to-handle-http-requests-and-create-useful-scripts/

Use that for automatically accepting certificate for https :

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

The method specified by Spyros should work and its the easiest trick around. But not the safest one as it involves security issues(not having peer verification is not recommended!).

An alternative is to download the certificate of the page you're trying to visit and save it under your project folder. Then use this code to give the certificate information to the cURL:

curl_setopt($ch, CURLOPT_CAINFO, getcwd().'/certificates/BuiltinObjectToken-EquifaxSecureCA.crt');

You can download the certificate easily from firefox by going to the paddle lock icon in the url bar.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM