473,324 Members | 2,268 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,324 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 1062

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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.