Jump to content

PHP Curl Check to see if Cookie exists from site you are visting


akphidelt2007

Recommended Posts

Alright, this might be a dumb question, but I've been messing with Curl and testing out different functions. One thing, I'm wondering is if there is a way to use curl to access a site and check to see if that site already has a cookie. For instance, if you access ESPN and you see that they have your Facebook info set up. Is there a way to use Curl to check to see if that Cookie exists. I'm using a localhost right now. So I might be missing something here about how to access cookies on your own computer/server. 

 

I would post some test code, but I don't even know where to begin. I know how to set cookies and check cookies for users accessing my sites, but for some reason can't figure out if a site I'm accessing through Curl has a cookie on me.

 

Any help will be appreciated. Thanks. 

Link to comment
Share on other sites

Sites don't have cookies, clients do. Every browser and also cURL manage their own cookies.

 

So whose cookies are you talking about? The cookies of cURL are stored in a simple text file which can be inspected at any time. If you want to check if the cookie is still accepted by the server, you would of course have to make a request and use heuristics to determine if that's the case (like parsing parts of the website or trying to access a page which is only accessible with a valid cookie).

Edited by Jacques1
Link to comment
Share on other sites

Sites don't have cookies, clients do. Every browser and also cURL manage their own cookies.

 

So whose cookies are you talking about? The cookies of cURL are stored in a simple text file which can be inspected at any time. If you want to check if the cookie is still accepted by the server, you would of course have to make a request and use heuristics to determine if that's the case (like parsing parts of the website or trying to access a page which is only accessible with a valid cookie).

 

I might be missing something here. But I'm talking about being the client and cookies that other sites have stored on my computer or server. Is there a way to check those through php to see if they exist? Like to check if I have a Cookie from ESPN and want to delete it before making a curl request. Not sure if it's possible or even makes sense. 

Link to comment
Share on other sites

Again, every web client has its own cookies. If you use, say, Firefox and get cookies from ESPN, those cookies only matter to Firefox. cURL doesn't use them at all. The cookies managed by cURL are entirely separate, and you're free to delete or ignore them as you like.

Link to comment
Share on other sites

Again, every web client has its own cookies. If you use, say, Firefox and get cookies from ESPN, those cookies only matter to Firefox. cURL doesn't use them at all. The cookies managed by cURL are entirely separate, and you're free to delete or ignore them as you like.

 

Ok, so let me just clarify what you're saying. When I go to ESPN.com and they have me logged in and are connected to my Facebook account through cookies that are located on my computer that they are accessing. When I use Curl to access ESPN through my localhost, ESPN does not have any cookies they can use to access from my computer like if I'm just using the browser myself?

Link to comment
Share on other sites

Cookies are associated with the client (eg browser) being used to access the site. This is why for example if you go to ESPN and login with Firefox, you will not be logged in if you later visit with Chrome. Firefox and Chrome have separate cookie stores, as would cURL.

 

It's not possible to use PHP (or cURL) to check if a user's browser has cookies for some third-party website.

Link to comment
Share on other sites

When I use Curl to access ESPN through my localhost, ESPN does not have any cookies they can use to access from my computer like if I'm just using the browser myself?

 

ESPN cannot access any files on your PC. That would be horrible. What happens is that the client (Firefox or cURL) includes its stored cookies in the request so that the server can read those cookies. You can actually see this if you open the developer tools of your browser (usually by hitting F12) and inspect the traffic.

 

It's very important to understand that cookies are managed client-side, which means they're under your control. You decide which cookies the server gets. You're free to send no cookies at all or even “fake” cookies created by yourself.

Edited by Jacques1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.