daydreamer Posted May 15, 2008 Share Posted May 15, 2008 hi. I am trying to use curl to post to a https page. in specific, i am trying to change a password. <?php $pw = 'smudge1'; $newpass = 'itworked'; //Go to password change page (after main page has logged in.) $curl = curl_init(); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_COOKIEFILE, 'cookiefile777'); curl_setopt($curl, CURLOPT_COOKIEJAR, 'cookiefile777'); # SAME cookiefile curl_setopt($curl, CURLOPT_POSTFIELDS, "in_oldPassword=$pw&in_newPassword=$newpass&Confirm_Password=$newpass&submit=Save"); curl_setopt($curl, CURLOPT_URL, 'https://registration.o2.co.uk/Registration/Update'); $xxx = curl_exec($curl); echo $xxx; curl_close ($curl); ?> The result is a page from the 02 server saying "Unfortunately a problem was encountered while trying to process your request.". Normally if you have entered any incorrect details this error would tell you what is wrong. Do i have to use curl_setopt to set something which enables https? Does anyone have any suggestions, questions, hints, tips, anything will help! Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/105799-using-curl-to-post-to-https/ Share on other sites More sharing options...
daydreamer Posted May 15, 2008 Author Share Posted May 15, 2008 ??? Quote Link to comment https://forums.phpfreaks.com/topic/105799-using-curl-to-post-to-https/#findComment-542272 Share on other sites More sharing options...
MadTechie Posted May 15, 2008 Share Posted May 15, 2008 have you used curl to login ? if not you can't change the password Quote Link to comment https://forums.phpfreaks.com/topic/105799-using-curl-to-post-to-https/#findComment-542284 Share on other sites More sharing options...
daydreamer Posted May 16, 2008 Author Share Posted May 16, 2008 yep i have, another script does that part. This script can defiantly get to the page where you enter the details of new password, old password etc, I have tested by echoing the result before the post attempt. The page also lets you change other details like name, address etc, but I want to keep these the same so have only included these details: curl_setopt($curl, CURLOPT_POSTFIELDS, "in_oldPassword=$pw&in_newPassword=$newpass&Confirm_Password=$newpass&submit=Save"); Should I be including the other parts as well (i have tried this tho, same error). Thanks for any help - if you need any other info please ask! Quote Link to comment https://forums.phpfreaks.com/topic/105799-using-curl-to-post-to-https/#findComment-542985 Share on other sites More sharing options...
daydreamer Posted May 16, 2008 Author Share Posted May 16, 2008 ??? Quote Link to comment https://forums.phpfreaks.com/topic/105799-using-curl-to-post-to-https/#findComment-543163 Share on other sites More sharing options...
daydreamer Posted May 16, 2008 Author Share Posted May 16, 2008 [move]a n y o n e ? ? ?[/move] Quote Link to comment https://forums.phpfreaks.com/topic/105799-using-curl-to-post-to-https/#findComment-543212 Share on other sites More sharing options...
DyslexicDog Posted May 17, 2008 Share Posted May 17, 2008 I just used cURL for the first time the other day and I found a nice class that made things easier than I thought they would be. Here's the class and the docs http://github.com/shuber/curl/tree/master <?php # Curl, CurlResponse # # Author Sean Huber - shuber@huberry.com # Date May 2008 # # A basic CURL wrapper for PHP # # See the README for documentation/examples or http://php.net/curl for more information about the libcurl extension for PHP class Curl { public $cookie_file = 'curl_cookie.txt'; public $headers = array(); public $options = array(); public $referer = ''; public $user_agent = ''; protected $error = ''; protected $handle; public function __construct() { $this->user_agent = $_SERVER['HTTP_USER_AGENT']; } public function delete($url, $vars = array()) { return $this->request('DELETE', $url, $vars); } public function error() { return $this->error; } public function get($url, $vars = array()) { if (!empty($vars)) { $url .= (stripos($url, '?') !== false) ? '&' : '?'; $url .= http_build_query($vars); } return $this->request('GET', $url); } public function post($url, $vars = array()) { return $this->request('POST', $url, $vars); } public function put($url, $vars = array()) { return $this->request('PUT', $url, $vars); } protected function request($method, $url, $vars = array()) { $this->handle = curl_init(); # Set some default CURL options curl_setopt($this->handle, CURLOPT_COOKIEFILE, $this->cookie_file); curl_setopt($this->handle, CURLOPT_COOKIEJAR, $this->cookie_file); curl_setopt($this->handle, CURLOPT_FOLLOWLOCATION, true); curl_setopt($this->handle, CURLOPT_HEADER, true); curl_setopt($this->handle, CURLOPT_POSTFIELDS, http_build_query($vars)); curl_setopt($this->handle, CURLOPT_REFERER, $this->referer); curl_setopt($this->handle, CURLOPT_RETURNTRANSFER, true); curl_setopt($this->handle, CURLOPT_URL, $url); curl_setopt($this->handle, CURLOPT_USERAGENT, $this->user_agent); # Format custom headers for this request and set CURL option $headers = array(); foreach ($this->headers as $key => $value) { $headers[] = $key.': '.$value; } curl_setopt($this->handle, CURLOPT_HTTPHEADER, $headers); # Determine the request method and set the correct CURL option switch ($method) { case 'GET': curl_setopt($this->handle, CURLOPT_HTTPGET, true); break; case 'POST': curl_setopt($this->handle, CURLOPT_POST, true); break; default: curl_setopt($this->handle, CURLOPT_CUSTOMREQUEST, $method); } # Set any custom CURL options foreach ($this->options as $option => $value) { curl_setopt($this->handle, constant('CURLOPT_'.str_replace('CURLOPT_', '', strtoupper($option))), $value); } $response = curl_exec($this->handle); if ($response) { $response = new CurlResponse($response); } else { $this->error = curl_errno($this->handle).' - '.curl_error($this->handle); } curl_close($this->handle); return $response; } } class CurlResponse { public $body = ''; public $headers = array(); public function __construct($response) { # Extract headers from response $pattern = '#HTTP/\d\.\d.*?$.*?\r\n\r\n#ims'; preg_match_all($pattern, $response, $matches); $headers = split("\r\n", str_replace("\r\n\r\n", '', array_pop($matches[0]))); # Extract the version and status from the first header $version_and_status = array_shift($headers); preg_match('#HTTP/(\d\.\d)\s(\d\d\d)\s(.*)#', $version_and_status, $matches); $this->headers['Http-Version'] = $matches[1]; $this->headers['Status-Code'] = $matches[2]; $this->headers['Status'] = $matches[2].' '.$matches[3]; # Convert headers into an associative array foreach ($headers as $header) { preg_match('#(.*?)\:\s(.*)#', $header, $matches); $this->headers[$matches[1]] = $matches[2]; } # Remove the headers from the response body $this->body = preg_replace($pattern, '', $response); } public function __toString() { return $this->body; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/105799-using-curl-to-post-to-https/#findComment-543373 Share on other sites More sharing options...
daydreamer Posted May 20, 2008 Author Share Posted May 20, 2008 tried it out, but no cake. Thanks for the suggestion though! Quote Link to comment https://forums.phpfreaks.com/topic/105799-using-curl-to-post-to-https/#findComment-546037 Share on other sites More sharing options...
BlueSkyIS Posted May 20, 2008 Share Posted May 20, 2008 what was the problem using that class? errors? Quote Link to comment https://forums.phpfreaks.com/topic/105799-using-curl-to-post-to-https/#findComment-546041 Share on other sites More sharing options...
paulman888888 Posted May 20, 2008 Share Posted May 20, 2008 this may sound silly but what is curl? I like to learn and would like to know a website that i can read to find out more. Can you help please? Quote Link to comment https://forums.phpfreaks.com/topic/105799-using-curl-to-post-to-https/#findComment-546074 Share on other sites More sharing options...
DyslexicDog Posted May 20, 2008 Share Posted May 20, 2008 It's the Client URL Library built into PHP. It's used for accessing other websites or other such items. Quote Link to comment https://forums.phpfreaks.com/topic/105799-using-curl-to-post-to-https/#findComment-546156 Share on other sites More sharing options...
MadTechie Posted May 20, 2008 Share Posted May 20, 2008 Should I be including the other parts as well (i have tried this tho, same error). Thanks for any help - if you need any other info please ask! I would assume your missing some details but without an account or even an O2 phone it very hard for me to say. Quote Link to comment https://forums.phpfreaks.com/topic/105799-using-curl-to-post-to-https/#findComment-546160 Share on other sites More sharing options...
DyslexicDog Posted May 21, 2008 Share Posted May 21, 2008 tried it out, but no cake. Thanks for the suggestion though! Can you post the code that didn't work? Quote Link to comment https://forums.phpfreaks.com/topic/105799-using-curl-to-post-to-https/#findComment-546230 Share on other sites More sharing options...
daydreamer Posted June 10, 2008 Author Share Posted June 10, 2008 The code that didn't work is in my first post - at the top of this thread. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/105799-using-curl-to-post-to-https/#findComment-562616 Share on other sites More sharing options...
TravisJRyan Posted June 11, 2008 Share Posted June 11, 2008 <?php curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); ?> See if that doesnt work for ya Quote Link to comment https://forums.phpfreaks.com/topic/105799-using-curl-to-post-to-https/#findComment-562753 Share on other sites More sharing options...
daydreamer Posted June 13, 2008 Author Share Posted June 13, 2008 nope still nada. thanks 4 the suggestion! Quote Link to comment https://forums.phpfreaks.com/topic/105799-using-curl-to-post-to-https/#findComment-565049 Share on other sites More sharing options...
Ally666 Posted July 19, 2008 Share Posted July 19, 2008 In your login bit to o2 is this not via the https protocol? I am trying to login to o2 (so you have got further then me :-) what i think you need to do is maintain the session from the login for the change of password. You could do this using the ob_start around the login curl_exec bit. Like I said I can't help / test as i've not managed to login lol. Quote Link to comment https://forums.phpfreaks.com/topic/105799-using-curl-to-post-to-https/#findComment-594148 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.