akphidelt2007 Posted August 19, 2016 Share Posted August 19, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/301944-php-curl-check-to-see-if-cookie-exists-from-site-you-are-visting/ Share on other sites More sharing options...
Jacques1 Posted August 19, 2016 Share Posted August 19, 2016 (edited) 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 August 19, 2016 by Jacques1 Quote Link to comment https://forums.phpfreaks.com/topic/301944-php-curl-check-to-see-if-cookie-exists-from-site-you-are-visting/#findComment-1536346 Share on other sites More sharing options...
akphidelt2007 Posted August 19, 2016 Author Share Posted August 19, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/301944-php-curl-check-to-see-if-cookie-exists-from-site-you-are-visting/#findComment-1536349 Share on other sites More sharing options...
Jacques1 Posted August 19, 2016 Share Posted August 19, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/301944-php-curl-check-to-see-if-cookie-exists-from-site-you-are-visting/#findComment-1536350 Share on other sites More sharing options...
akphidelt2007 Posted August 19, 2016 Author Share Posted August 19, 2016 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? Quote Link to comment https://forums.phpfreaks.com/topic/301944-php-curl-check-to-see-if-cookie-exists-from-site-you-are-visting/#findComment-1536351 Share on other sites More sharing options...
kicken Posted August 19, 2016 Share Posted August 19, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/301944-php-curl-check-to-see-if-cookie-exists-from-site-you-are-visting/#findComment-1536352 Share on other sites More sharing options...
Jacques1 Posted August 19, 2016 Share Posted August 19, 2016 (edited) 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 August 19, 2016 by Jacques1 Quote Link to comment https://forums.phpfreaks.com/topic/301944-php-curl-check-to-see-if-cookie-exists-from-site-you-are-visting/#findComment-1536353 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.