Some websites force cookie usage to open a https page, So i've written this function to make it easier. To use it just create a cookie.txt file and allow write permission.
<?php
/**
* Open an url on https using curl and return content
*
* @author hatem <info@phptunisie.net>
* @param string url The url to open
* @param string refer Referer (optional)
* @param mixed usecookie If true, cookie.txt will be used as default, or the usecookie value.
* @return string
*/
function open_https_url($url,$refer = "",$usecookie = false) {
if ($usecookie) {
if (file_exists($usecookie)) {
if (!is_writable($usecookie)) {
return "Can't write to $usecookie cookie file, change file permission to 777 or remove read only for windows.";
}
} else {
$usecookie = "cookie.txt";
if (!is_writable($usecookie)) {
return "Can't write to $usecookie cookie file, change file permission to 777 or remove read only for windows.";
}
}
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
if ($usecookie) {
curl_setopt($ch, CURLOPT_COOKIEJAR, $usecookie);
kailash agrawal wrote :1698
I use this code exactly as shown on this url.
$url="https://secure.jetairways.com/jetobe/onlinebooking.aspx?";
cookie.txt file is created with 0 bytes.
However, the website just hangs after that. No data is returned back. Nothing happens.
I tried it 1 other https website, and the same thing happens. If I use these url on a browser, they work just fine. I would appreciate, if you help me find out what`s missing. I`ve tried many forums with no success.