Hello, I am having trouble with parsing a xml file which is coming using a secured (https : //) file location and also need http password to view. How can I parse it with php. I used parsing as normally did but its giving permission error " You have no permission to view the page .......and so on... " Please guide me how to accomplish this. Thanks
Does your server have php_openssl installed and present? You can run this test to see if it is. <?php echo ' <h1>Testing for OpenSSL and HTTPS</h1> <p>OpenSSL ', extension_loaded('openssl') ? 'Loaded' : 'Not Found', '</p> <p>HTTPS ', in_array('https', stream_get_wrappers()) ? 'Available' : 'Not Found', '</p>'; ?> Code (markup): If either condition reports 'not found' you need to enable it. One would hope openSSL is installed, meaning you just need to enable it in your php.ini -- look for a line that starts with something like this: (linux version) ;extension=php_openssl.so (windows version) ;extension=php_openssl.dll Uncomment it (remove the semi-colon). If you can't find it, add it to the end of the file. That should do the trick if that's indeed your problem.
are you passing the username/password for the http pw in the URI? https://username:password@domain.com for example?
Thanks. I need to make some clear about requirements. My browser url is like http:// domain.com/test_xml.php (here no https no password required) But from script using curl I send the url which is https and http authentication required. May be i need to send username password along with url through curl parameter but I am not getting it how to do. Please let men know if its not clear. Thanks anyway.
You should be able to set it in your curl_setopt/CURLOPT_URL line since that's where logins are passed. Could you post up the CURL code you are using to connect? hard to figure out where your problem might lay without the code.
$kn = ""; $leaf = "808"; $url = "https://xxxx.xx/GetPriceBatch?ndl=101&pfart=DEB&mode=VKB&kn=".$kn."&leafsid=".$leaf.""; echo "<br />Path: " . $url; try { $agents = array( 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0 FirePHP/0.7.4', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:7.0.1) Gecko/20100101 Firefox/7.0.1', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100508 SeaMonkey/2.0.4', 'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)', 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; da-dk) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1' ); $header[] = "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"; $header[] = "Cache-Control: max-age=0"; $header[] = "Connection: keep-alive"; $header[] = "Keep-Alive: 300"; $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"; $header[] = "Accept-Language: en-us,en;q=0.5"; $header[] = "Pragma: "; // browsers keep this blank. $ch = curl_init(); curl_setopt($ch, CURLOPT_USERAGENT,$agents[array_rand($agents)]); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_URL, $url); //set the $url to where your request goes curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //set this flag for results to the variable curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); //This is required for HTTPS certs if curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); //you don't have some key/password action curl_setopt($ch, CURLOPT_AUTOREFERER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); /* execute the request */ $ausgabe = curl_exec($ch); if (curl_errno($ch)) { print "Error: " . curl_error($ch); } curl_close($ch); var_dump($ausgabe ); echo "<br /><xmp>Ausgabe: " . $ausgabe . "</xmp>"; } catch (Exception $e) { echo 'Exception : ', $e->getMessage(), "\n"; } Code (markup):
Actually, I stand corrected. Apparantly it IS a separate curlOpt parameter. curl_setopt($ch, CURLOPT_USERPWD, 'username:password'); Code (markup): Add that alongside your other curl_setopt and it should log in. Been a while since I've used cURL.