drupalphp Posted February 22, 2014 Share Posted February 22, 2014 Hey guys I am new here, I am trying to Get from my Api,Im using curl in php to log into on one page and then get another page passing all cookies from the first page along with you but I keep getting Access denied!! $ch = curl_init(); curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookieFileName"); curl_setopt($ch, CURLOPT_URL,"http://www.supersaas.com/api/users"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, "?account=myname&password=mypassword"); ob_start(); // prevent any output curl_exec ($ch); // execute the curl command ob_end_clean(); // stop preventing output curl_close ($ch); unset($ch); $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookieFileName"); curl_setopt($ch, CURLOPT_URL,"http://www.supersaas.com/api/users?id=12"); $buf2 = curl_exec ($ch); curl_close ($ch); echo "<PRE>".htmlentities($buf2); What's wrong with the code???? Quote Link to comment https://forums.phpfreaks.com/topic/286395-login-to-on-one-page-and-then-get-another-page-help/ Share on other sites More sharing options...
WebStyles Posted February 22, 2014 Share Posted February 22, 2014 I didn't check out the API, so I'm just guessing here, but normally these remote logins require an encrypted password. Are you hashing yours before you send it? Quote Link to comment https://forums.phpfreaks.com/topic/286395-login-to-on-one-page-and-then-get-another-page-help/#findComment-1469948 Share on other sites More sharing options...
jazzman1 Posted February 22, 2014 Share Posted February 22, 2014 (edited) Double check the name and value attributes and their values. This works for me -> #!/bin/bash NAME='jazz' PASS='jazz' REMEMBER='R' curl --cookie-jar cjar --output /dev/null 'http://www.supersaas.com' curl --cookie cjar --cookie-jar cjar --data 'name='${NAME} --data 'password='${PASS} --data 'remember='${REMEMBER} --location \ 'http://www.supersaas.com/dashboard/login' Edited February 22, 2014 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/286395-login-to-on-one-page-and-then-get-another-page-help/#findComment-1469961 Share on other sites More sharing options...
drupalphp Posted February 22, 2014 Author Share Posted February 22, 2014 I can log in to the first page, but I cant log in to the second page, I assume something wrong with my cookies. Quote Link to comment https://forums.phpfreaks.com/topic/286395-login-to-on-one-page-and-then-get-another-page-help/#findComment-1469962 Share on other sites More sharing options...
jazzman1 Posted February 22, 2014 Share Posted February 22, 2014 (edited) Post the source code of this html form of the second page. Edited February 22, 2014 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/286395-login-to-on-one-page-and-then-get-another-page-help/#findComment-1469963 Share on other sites More sharing options...
drupalphp Posted February 22, 2014 Author Share Posted February 22, 2014 Post the source code of this html form of the second page. This is my source code.. I can log in and pull the data manually, but it doesnt work with the code.. now when I log in to the first page it return xml file I use this url (http://www.supersaas.com/api/users?account=myname&password=mypassword) , than I try to run a filler in order the get user id that I need ( curl_setopt($ch, CURLOPT_URL,"http://www.supersaas.com/api/users?id=12"); ) than I am getting " HTTP Basic: Access denied. ", I hope it clear now, THANKS A LOT Quote Link to comment https://forums.phpfreaks.com/topic/286395-login-to-on-one-page-and-then-get-another-page-help/#findComment-1470082 Share on other sites More sharing options...
jazzman1 Posted February 22, 2014 Share Posted February 22, 2014 Works for me. #!/bin/bash NAME='jazz' PASS='jazz' curl --cookie-jar cjar --output /dev/null 'http://www.supersaas.com' curl --cookie cjar --cookie-jar cjar --location \ "http://www.supersaas.com/api/users?account=${NAME}&password=${PASS}" Result: [jazz@centos-box ~]$ ./curl % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed100 14530 100 14530 0 0 44949 0 --:--:-- --:--:-- --:--:-- 67897 <?xml version="1.0" encoding="UTF-8"?><nil-classes type="array"/> Quote Link to comment https://forums.phpfreaks.com/topic/286395-login-to-on-one-page-and-then-get-another-page-help/#findComment-1470120 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.