Asked  7 Months ago    Answers:  5   Viewed   31 times

I would like to understand the four options of cURL for cookies:


I understand that COOKIEJAR is meant for writing cookies, and COOKIEFILE is meant for reading. So what is COOKIESESSION for ? The CURLOPT_COOKIE is custom, but can I use it to maintain a session with the server ?



To understand CURLOPT_COOKIESESSION, you need to know a couple of things about cookies. Cookies have expiration dates that are set by the website that issues the cookie. If an expiration date of a cookie has passed, the browser/client will not send it, and it will be deleted by the client. If a cookie is set with NO expiration date, the browser should use that cookie until the browser session is closed, or the user logs out and the cookie gets unset.

That said, CURLOPT_COOKIESESSION is a way to get cURL to simulate having closed the browser. If the COOKIEFILE has some session cookies in it (cookies with no expiration), it will normally send these if they were present in the file. If you set CURLOPT_COOKIESESSION, then it will NOT send any of the cookies that have no expiration date.

CURLOPT_COOKIE just gives you a means of setting the cookie data that will be sent to the server in raw format. This is useful if for example you have a raw HTTP cookie that you would like to send. Without this option, you would have to get those cookies into the COOKIEFILE, or set a custom HTTP header Cookie: with the raw value you had.

Wednesday, March 31, 2021
answered 7 Months ago

You should only call curl_close() when you know you're done with that particular handle, or if switching from its current state to a new one (ie: changing a ton of options via curl_setopt() would be faster by going from a clean new handle than your current "dirty" one.

The cookiejar/file options are only strictly necessary for maintaining cookies between seperate curl handles/invokations. Each one's independent of the others, so the cookie files are the only way to share between them.

Wednesday, March 31, 2021
answered 7 Months ago

You need to add the Curl libraries to the command line PHP.ini.

You can probably just copy the file C:wampbinapacheApache2.2.xbinphp.ini to c:wampbinphpphp5.3.10php.ini (adjust for the actual directories on your system).

Wednesday, March 31, 2021
answered 7 Months ago

You can extract all cookies current url by this way from webview as string:

public void onPageFinished(WebView view, String url){
    String cookies = CookieManager.getInstance().getCookie(url);
    Log.d(TAG, "All the cookies in a string:" + cookies);
Thursday, June 3, 2021
answered 5 Months ago

The main difference is that when you use cookie[:foo] = 'bar' the user is able to see the value for the cookie, i.e. 'bar'. When you use session[:foo] = 'bar' the value will be encrypted by rails and stored in the _myapp_session cookie.

You would use the cookie[] format when the information you want to store is not bound to the session, e.g. when the users selects the preferred language.

You would use the session[] format when you want to store information that is related to the current session, e.g. the id of the the user.

Friday, September 3, 2021
Ramazan Polat
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :