daydreamer Posted February 3, 2008 Share Posted February 3, 2008 Aim: To automatically log into 02.co.uk, so that the server loads the compose text page automatically. This is what i have so far: <?php // This block of code is me trying to enter my details $ch = curl_init(); curl_setopt($ch, CURLOPT_COOKIEJAR, "/username"); // login wont work with cookies disbled - so have to handle cookies to emulate browers - this is my attempt probably wrong. their is a cookie called /username, along with 16 others. curl_setopt($ch, CURLOPT_URL,"http://www.o2.co.uk/login?dest=http://sendtxt.o2.co.uk/sendtxt/action/compose"); // page where form is located curl_setopt($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); // attempt to emulate client browser curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, "USERNAME=e_n_z_o&PASSWORD=12345"); $Result = curl_exec ($ch); echo $Result; // trying to login, or push the log in button mechanically. curl_setopt($ch, CURLOPT_URL,"https://zarkov.shop.o2.co.uk/login/mblogin"); // first page you go to after you sucessfully log in. if i manually enter in my login details, then put this url into brower, it will log me in. $Result = curl_exec ($ch); echo $Result; exit; ?> Questions: 1. The form has id=username, name=USERNAME. Which one should I be using in my code? 2. Do I have to take care of all the cookies, or just the username one? 3. Can you help me?! Quote Link to comment https://forums.phpfreaks.com/topic/89270-curl-help-needed-automatic-login/ Share on other sites More sharing options...
KrisNz Posted February 3, 2008 Share Posted February 3, 2008 1. The name field. 2. CURLOPT_COOKIEJAR should be set to the name of a file where curl can store all cookie information. You also need to set CURLOPT_COOKIEFILE to the same path so it can be retrieved. The login form posts to... https://zarkov.shop.o2.co.uk/login/mblogin Thats the url you want to post to. You need to look at the form and make sure you account for every input in that form - such as 'ACTION', 'dest' and 'fu'. Manual page - look for an example from Michael Sky 3. I hope I just did. Quote Link to comment https://forums.phpfreaks.com/topic/89270-curl-help-needed-automatic-login/#findComment-457159 Share on other sites More sharing options...
daydreamer Posted February 5, 2008 Author Share Posted February 5, 2008 hey thanks... what do you mean make sure you account for every input in that form - such as 'ACTION', 'dest' and 'fu'. Name Value ACTION LOGIN dest http://sendtxt.o2.co.uk/sendtxt/action/compose fu http://www.o2.co.uk/logerror?sendTo=http://sendtxt.o2.co.uk/sendtxt/action/compose What should I do with these? This is the code so far... <?php // source = micharl skys post http://us.php.net/manual/en/function.curl-setopt.php $curl = curl_init(); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_POST, true); 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, "cookiefile"); curl_setopt($curl, CURLOPT_COOKIEJAR, "cookiefile"); # SAME cookiefile curl_setopt($curl, CURLOPT_URL, "http://www.o2.co.uk/login?dest=http://sendtxt.o2.co.uk/sendtxt/action/compose"); # this is where you first time connect - GET method authorization in my case, if you have POST - need to edit code a bit $xxx = curl_exec($curl); curl_setopt($curl, CURLOPT_URL, "https://zarkov.shop.o2.co.uk/login/mblogin"); # this is where you are requesting POST-method form results (working with secure connection using cookies after auth) curl_setopt($curl, CURLOPT_POSTFIELDS, "USERNAME=e_n_z_o&PASSWORD=smudge1"); # form params that'll be used to get form results $xxx = curl_exec($curl); curl_close ($curl); echo $xxx; ?> Quote Link to comment https://forums.phpfreaks.com/topic/89270-curl-help-needed-automatic-login/#findComment-458189 Share on other sites More sharing options...
Northern Flame Posted February 5, 2008 Share Posted February 5, 2008 why not just do this? <form name="o2portal_sign_in_form" method="post" action="https://zarkov.shop.o2.co.uk/login/mblogin"> <input type="hidden" name="ACTION" value="LOGIN" /> <input type="hidden" name="dest" value="http://www.o2.co.uk" /> <input type="hidden" name="fu" value="http://www.o2.co.uk/logerror?sendTo=http://www.o2.co.uk" /> Username: <input type="text" name="USERNAME" id="username" value="" size="24" maxLength="30" /> <br /> Password: <input type="password" name="PASSWORD" id="password" value="" size="24" maxLength="16" /> <input type="submit" id="bdone" name="bdone" value="Log me in" title="Done" /> Quote Link to comment https://forums.phpfreaks.com/topic/89270-curl-help-needed-automatic-login/#findComment-458196 Share on other sites More sharing options...
CerealBH Posted February 5, 2008 Share Posted February 5, 2008 why not just do this? <form name="o2portal_sign_in_form" method="post" action="https://zarkov.shop.o2.co.uk/login/mblogin"> <input type="hidden" name="ACTION" value="LOGIN" /> <input type="hidden" name="dest" value="http://www.o2.co.uk" /> <input type="hidden" name="fu" value="http://www.o2.co.uk/logerror?sendTo=http://www.o2.co.uk" /> Username: <input type="text" name="USERNAME" id="username" value="" size="24" maxLength="30" /> <br /> Password: <input type="password" name="PASSWORD" id="password" value="" size="24" maxLength="16" /> <input type="submit" id="bdone" name="bdone" value="Log me in" title="Done" /> this has absolutely nothign 2 do with the topic, much like my post i use this 4 cookies $randnum = rand(1,9999999); curl_setopt($this->ch, CURLOPT_COOKIEJAR, $this->dir_path."/tmp/cookiejar-$randnum"); curl_setopt($this->ch, CURLOPT_COOKIEFILE, $this->dir_path."/tmp/cookiejar-$randnum"); Quote Link to comment https://forums.phpfreaks.com/topic/89270-curl-help-needed-automatic-login/#findComment-458201 Share on other sites More sharing options...
Northern Flame Posted February 5, 2008 Share Posted February 5, 2008 well it seems to me that all hes trying to do is login users from his website to another one, so why use cURL() when u can just make a simple form? Quote Link to comment https://forums.phpfreaks.com/topic/89270-curl-help-needed-automatic-login/#findComment-458202 Share on other sites More sharing options...
CerealBH Posted February 5, 2008 Share Posted February 5, 2008 not his website Quote Link to comment https://forums.phpfreaks.com/topic/89270-curl-help-needed-automatic-login/#findComment-458203 Share on other sites More sharing options...
daydreamer Posted February 5, 2008 Author Share Posted February 5, 2008 hey thanks for the example. This is why i want to do it with cURL and not a form.. I have more than one 02 account. Each has a limit of 10 txts a month. On my personal site, i want to show the To and Message boxs and send text boxs in my own layout design. After the first 10 texts get used up, i want the php script to automatically log into the next account, and use those txts on tht account. I dont want to have to put username or password in everytime i need to switch accounts (or ever). Also i want to learn some PHP and thought this would be a good project... The learning continues... anyway my above code just forwards me to the 02 website ???... anyone know why or what I should do to my code?! Hey cerealBH.. what does this do in ur cookie code (specially the -> part) ?: $this->dir_path. Quote Link to comment https://forums.phpfreaks.com/topic/89270-curl-help-needed-automatic-login/#findComment-458224 Share on other sites More sharing options...
CerealBH Posted February 5, 2008 Share Posted February 5, 2008 its refering to the class that i was working in, u can disregard the $this-> adn change it to #dir_path. Quote Link to comment https://forums.phpfreaks.com/topic/89270-curl-help-needed-automatic-login/#findComment-458229 Share on other sites More sharing options...
KrisNz Posted February 5, 2008 Share Posted February 5, 2008 what do you mean make sure you account for every input in that form - such as 'ACTION', 'dest' and 'fu'. Name Value ACTION LOGIN dest http://sendtxt.o2.co.uk/sendtxt/action/compose fu http://www.o2.co.uk/logerror?sendTo=http://sendtxt.o2.co.uk/sendtxt/action/compose I mean that they should all be part of your CURLOPT_POSTFIELDS string. The code that processes the login will be expecting them and will be part (if not all) of the reason you're getting bumped back to the homepage. Quote Link to comment https://forums.phpfreaks.com/topic/89270-curl-help-needed-automatic-login/#findComment-458299 Share on other sites More sharing options...
daydreamer Posted February 5, 2008 Author Share Posted February 5, 2008 cheers... ok so added fu, dest and ACTION all to the CURLOPT_POSTFIELDS string. As seen: <?php $fu="http://www.o2.co.uk/logerror?sendTo=http://sendtxt.o2.co.uk/sendtxt/action/compose"; $dest="http://sendtxt.o2.co.uk/sendtxt/action/compose"; $curl = curl_init(); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_POST, true); 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, "cookiefile"); curl_setopt($curl, CURLOPT_COOKIEJAR, "cookiefile"); # SAME cookiefile curl_setopt($curl, CURLOPT_URL, "http://www.o2.co.uk/login?dest=http://sendtxt.o2.co.uk/sendtxt/action/compose"); # this is where you first time connect - GET method authorization in my case, if you have POST - need to edit code a bit $xxx = curl_exec($curl); curl_setopt($curl, CURLOPT_URL, "https://zarkov.shop.o2.co.uk/login/mblogin"); # this is where you are requesting POST-method form results (working with secure connection using cookies after auth) curl_setopt($curl, CURLOPT_POSTFIELDS, "USERNAME=e_n_z_o&PASSWORD=smudge1&ACTION=LOGIN&dest=$dest&fu=$fu"); # form params that'll be used to get form results $xxx = curl_exec($curl); curl_close ($curl); echo $xxx; ?> This takes me to the login page.. without logging in. The page is http://www.o2.co.uk/login?dest=http://sendtxt.o2.co.uk/sendtxt/action/compose. any ideas? - appreciate the help man! going to be working on this script tonight. Quote Link to comment https://forums.phpfreaks.com/topic/89270-curl-help-needed-automatic-login/#findComment-458514 Share on other sites More sharing options...
GingerRobot Posted February 5, 2008 Share Posted February 5, 2008 I suggest you use firefox, along with the live HTTP headers addon to help you analyse everything that is being sent when you make the request yourself. It might help you identify something missing from your automated request. Its a very useful tool when dealing with cURL requests. Quote Link to comment https://forums.phpfreaks.com/topic/89270-curl-help-needed-automatic-login/#findComment-458518 Share on other sites More sharing options...
GingerRobot Posted February 5, 2008 Share Posted February 5, 2008 Forgot to post the link: https://addons.mozilla.org/en-US/firefox/addon/3829 Quote Link to comment https://forums.phpfreaks.com/topic/89270-curl-help-needed-automatic-login/#findComment-458526 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.