473,396 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Authorize with curl and login into a page to parse html not working

134 100+
I'm trying to read a html page using simple html dom for which an login authorization is needed.

for example: http://example.com/login/ is the login page and http://example.com/page/ is where i should parse the html.

So i used curl to do the login and simple html dom to parse.

But i dont know whether my page login or not, because when i display the response from curl its the login page contents!!

I searched through stack in allmost all related questions for many hours but i couldnt find what is going wrong.

below is my code
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $curlPost['username']="username";
  3. $curlPost['password']="pass";
  4. $curlPost['token']="xxxxxxxxxx";
  5.  
  6. $ch = curl_init();
  7. curl_setopt($ch, CURLOPT_URL , "http://example.com/login/");
  8. curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13");
  9. curl_setopt($ch, CURLOPT_POST, 1);
  10. curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
  11. curl_setopt($ch, CURLOPT_HEADER, true);
  12. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
  13. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  14. curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
  15. curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt");
  16. $response= curl_exec ($ch);
  17. curl_close($ch);
  18.  
  19. $ch = curl_init();
  20. curl_setopt($ch, CURLOPT_URL , "http://example.com/page/");
  21. curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13");
  22. curl_setopt($ch, CURLOPT_HEADER, true);
  23. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
  24. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  25. curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
  26. curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt");
  27. $reponse= curl_exec ($ch);
  28. curl_close($ch);
  29.  
  30. echo $response;
  31. ?>
  32.  
Below is what i get in response in the top of my page:
"
HTTP/1.1 302 Found
Date: Wed, 28 Jan 2015 06:59:44 GMT
Server: Apache
X-Powered-By: PHP/5.3.3
Cache-Control: no-cache
Location: /login
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8

HTTP/1.1 200 OK
Date: Wed, 28 Jan 2015 06:59:45 GMT
Server: Apache
X-Powered-By: PHP/5.3.3
Cache-Control: no-cache
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8
"
followed by the login page html contents.

And I didn't see any changes happening to "cookies.txt" file, even tried giving fullpath.

I think the script is not logging in correctly even-though when the credentials are correct.

Anyone can advise me on what i'm doing wrong.

Many thanks.
Jan 29 '15 #1
0 1065

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: amit.purohit | last post by:
hi, I have a very strange problem on my login Page. the Page was working fine a few days back, but now does not generate post back events for controls. this login page uses form based...
3
by: Dam6 | last post by:
Okay... Using vb .net within DW MX2004, connecting to an access database: Background: I have created a simple login.aspx page that is supposed to re-direct to default.aspx using...
2
by: Sasquatch | last post by:
I'm having trouble creating a simple login page using the asp:login control. I followed some instructions in a WROX book, "Beginning ASP.NET 2.0," and the instructions are very straight forward,...
2
by: Sasquatch | last post by:
I'm still having trouble creating a simple login page using the asp:login control. I followed some instructions in a WROX book, "Beginning ASP.NET 2.0," and the instructions are very straight...
4
tolkienarda
by: tolkienarda | last post by:
Hi all I work for a small webdesign company and we have remote hosting. i built a mysql database with phpmyadmin on the server. i then downloaded and modified a php login page. i am continuing to...
3
by: Sleepwalker | last post by:
Hi, I'm currently working on creating a stripped down part of a company web page, that will be accessed from cellphone. The problem I have is that the Windows Forms authentication makes it...
2
by: dgbergman | last post by:
I have created a php login page in my site for my company. The goal is to get people into members area. Below is a list of steps that I take to create my login page in Dreamweaver CS3, can some one...
0
by: Anup Daware | last post by:
Hi All, I am facing this very weird issue, for every server request my control is redirecting to the login page and again coming back to the actual page from where the request was initiated when I...
9
by: adweaver | last post by:
Hello All, I'm new to the world of php. I've just had a site designed for me by a company, and I'm now trying to manage and grow it, so it will suit my needs. The site was built in a folder...
2
by: jesposito | last post by:
I have seen numerous posts with this problem, however none of the solutions have worked for me. I am using asp.net 4.0 forms authentication. I have the following set in my config file. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.