E
E
Express7772016-03-11 08:57:13
PHP
Express777, 2016-03-11 08:57:13

How to handle JS cookies in PHP?

Hello dear.
The task is to get data from the site, parse through PHP
Here are the methods that I used
1. file_get_contents(). But

failed to open stream: HTTP request failed! HTTP/1.1 500 ( The specified network name is no longer available. )

2. Used CURL as a google bot.
https://github.com/izniburak/google-bot-curl/blob/...
But I get such a result, or rather I get nothing. After about 40 seconds
request time out
3. Used CURL, sent by Chrome agent user.
I get this result, I formatted the code to make it more convenient:
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <script type="text/javascript">
  document.cookie='cookieName=cookieToken; max-age=604800; path=/; domain=.examle.com;'; 
  var nc = function() {
    return document.cookie.indexOf('cookieName=cookieToken')==-1;
  };
  var w = function() {
    document.body.innerHTML = document.getElementsByTagName('noscript')[0].textContent;
  };

if (!window.opera) {
  
  if (!nc()) {
    window.location.reload(true);
  }
  
  var r = function() {
    if (nc()) w();
  };

} 

else {var r = function () {if (!nc()) {window.location.reload(true);}else {w();}}}</script>

</head>
<body onload="r()">
  <noscript>You have to turn on javascript and cookies support in browser to visit this site.<br>
    Для посещения этого сайта необходима поддержка javascript и cookies Вашим браузером<br>
    <a href="https://ddos-guard.net">https://ddos-guard.net</a></noscript>
</body>

</html>

4. Used phantomJs. Launched through the console, not through PHP.
Code
Link to pastebean, due to character limit
JS Code The
response in both test1.html and test2.html is the same as the Curl request, only without the body.
pastebin.com/qAfGBDeL
Thinking out loud. This script sets cookies via JS. Then it checks for its presence, if there is no cookie, then reloads the page. Since cookies are stored in the browser, the next time you visit the cookie is already there.
Checks if there are cookies. There are cookies and there is no need to reload the page, you need to display the content
How to get a normal page with content?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry, 2016-03-11
@thewind

Have you tried the cookie jar file option in curl? If the cookie is set not only through js, but also through response headers, then it will be pushed into this array, and the follow location option in curl will allow you to "refresh" the page by sending the desired cookie to the server. All this will only work if the js functions are duplicated in the server headers.

E
enchikiben, 2016-03-11
@EnChikiben

you can just go to the site in the browser, get the cookie, copy it and paste it into the bot

D
Danil Sapegin, 2016-03-11
@ynblpb_spb

In phantomjs, you need to specify the path to the cookie file and everything will work. Read the documentation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question