Answer the question
In order to leave comments, you need to log in
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. )
request time out
<!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>
Answer the question
In order to leave comments, you need to log in
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.
you can just go to the site in the browser, get the cookie, copy it and paste it into the bot
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 questionAsk a Question
731 491 924 answers to any question