By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,278 Members | 1,342 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,278 IT Pros & Developers. It's quick & easy.

Problem with PHP CURL script

P: 14
Hello,

I am trying to access a website which is hosted on secure server. Code looks as follows,

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. //open connection   
  4. $ch = curl_init();   
  5.  
  6. //set the url, number of POST vars, POST data   
  7. curl_setopt($ch,CURLOPT_URL,"http://web2.westlaw.com/signon/default.wl");
  8. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  2);
  9. curl_setopt($ch, CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
  10. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  11. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  12.  
  13. //execute post   
  14. $result = curl_exec($ch);   
  15.  
  16. //close connection   
  17. curl_close($ch);
  18.  
  19. echo $result;
  20.  
  21. ?>
This web page has a redirect javascript at top which detects frame name and if no frame is found, the page is redirected using "location.href" method.

Due to this method, the page is refreshed but with the local address i.e. http://localhost:8080/test_project/signon/default.wl and hence, it gives, page cannot be found error. How can I overcome this problem ?

Thanks,
Sandeep
Aug 27 '08 #1
Share this Question
Share on Google+
4 Replies


Atli
Expert 5K+
P: 5,058
Hi.

I may be wrong here, but I don't think a Javascript redirect would have any effect on a Curl request.
Javascript is executed client-side, which would require a browser capable of executing Javascript code.
As far as I know, Curl would simply return the Javascript code as plain text.

One thing about that code...
Shouldn't a request to a secure page start with https?
Aug 28 '08 #2

P: 14
Hi Atli,

Thanks for the reply :)

I am pointing to 'https' website. That's a typo in my post.

Regarding javascript redirect, I was referring to the action after CURL script execution. I'll put forward some more description about my script.

I am executing script on local server as,
http://localhost:8080/test_project/test_curl.php

I am pointing to 'https://web2.westlaw.com/signon/default.wl' through CURL. When I execute the script, browser address bar shows,
http://localhost:8080/signon/default.wl

As you can see, URL part next to domain name is appended over here (signon/default.wl) That's why, I was thinking that the page on Westlaw was submitting to itself. If you do view->source on 'https://web2.westlaw.com/signon/default.wl', you would see following code at top.

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. <!--
  3.     var getCorrectFN = null;
  4.     if (document.referrer != '') {
  5.         getCorrectFN = document.referrer;
  6.         getCorrectFN = getFrameName(getCorrectFN);
  7.     }
  8.  
  9.     if (getCorrectFN == "_top" || getCorrectFN == "WestlawFrameWithChat" || getCorrectFN == "%5Ftop") {
  10.         if (top.location != location) {
  11.             top.location.href = location.href;
  12.         }
  13.     }
  14.     else if (getCorrectFN != null && getCorrectFN.length > 0) {
  15.         getWestlawFrameReference(getCorrectFN).location.href = location.href;
  16.     }
  17.     if (window.parent == window) {
  18.         if (top.name != "FromEW") {
  19.             top.name = '';
  20.         }
  21.     }
  22. //-->
  23. </script>
One more observation. When you open 'https://web2.westlaw.com/signon/default.wl', a small blank popup opens in right bottom corner which closes itself within 5-10 seconds. When I execute my script, a popup opens with same 'Page cannot be found' error as in the parent window.

I hope, I have explained the problem in a better way now.

Thanks,
Sandeep
Aug 29 '08 #3

Atli
Expert 5K+
P: 5,058
Why does the URI change after the Curl code has been executed?
Do you echo the result you get from Curl?

As far as I know, Curl shouldn't do anything with the code it gets from the response. Any Javascript would be stored as text, only executed if you decide to use it.

So, we can't really know why this is happening unless we know what your PHP code is doing.
It would really help if we could see that code.
Aug 30 '08 #4

P: 14
Hi Atli,

I have already posted the code. That's the only piece of code, I have.

Could this be due to some session check on website. I am saying so because even if I JUST try to access the website with CURL script (without the post arguments), same action takes place and browser shows "Page cannot be found".

Thanks,
Sandeep
Aug 31 '08 #5

Post your reply

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