Reputation:
Hullo, I need to open a page with file_get_html featuring it with two cookies a get from another page. How do I collect the cookies from the former page and submit them to the latter?
Upvotes: 0
Views: 6756
Reputation: 3694
In JavaScript first:
As JavaScript is a client side language, so there is no need to pass the cookies, but if you are calling a URL of some different domain then you have to use jquery.getjson, as cross domain is not allowed in javascript
Second in PHP, you can pass the cookies through curl, there is a operation in curl which is curl_setopt($session, CURLOPT_COOKIE, $cookie)
. At any time you can get the cookies by $_COOKIE
.
Upvotes: 0
Reputation: 2021
First of all if your working with cookies the best is to set the cookie on a Domain base:
So lets say your domain is www.somesite.com
//This cookie will expire in one hour.
$expire=time()+3600; setcookie("user", $value, $expire, "/","somesite.com");
Now to read the cookie on another page with the same domain
echo $_COOKIE["user"];
If you want to test your cookies better in your browser i recommend you use firefox with firebug and firecookie addons in that way you will see all your cookies and you can even edit them and understand the way they work on a browser.
To download firefox: http://www.mozilla.org/en-US/firefox/fx/
To get the firebug: http://getfirebug.com/
To get the firecookie: https://addons.mozilla.org/en-US/firefox/addon/firecookie/
Better not to use cookies if the data is sensitive as the cookie can be manipulated from the client side... if you want to secure more the data you can use combination of cookie and session.
Regards, Gabriel
Upvotes: 1