$url = 'https://example.com/api/login';
# Initialize cURL session
$curlObj = curl_init();
# Set cURL options
curl_setopt($curlObj, CURLOPT_POST, 1);
curl_setopt($curlObj, CURLOPT_POSTFIELDS, 'email=email&password=password');
curl_setopt($curlObj, CURLOPT_URL, $url);
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlObj, CURLOPT_HEADER, 1);
curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, false);
# Execute cURL session
$result = curl_exec($curlObj);
# Close cURL session
curl_close($curlObj);
# Extract cookies from the response headers
preg_match_all('/^Set-Cookie:\\s*([^;]*)/mi', $result, $match_found);
$cookies = array();
foreach ($match_found[1] as $item) {
parse_str($item, $cookie);
$cookies = array_merge($cookies, $cookie);
}
# Display extracted cookies
print_r($cookies);cURL Login with Cookie Extraction
Related Posts
More content you might like
Tutorial
php
Integrating and Using NMI Payment Gateway in Laravel
Once a customer is added to the vault, you can process payments using their vault ID. Let’s add a method for this.
Add the following method to the NMI class:
Aug 14, 2024
Read More Tutorial
python
Creating a Simple REST API with Flask
- Delete an item:
curl -X DELETE http://127.0.0.1:5000/api/items/3Aug 03, 2024
Read More Code
bash
Various cURL Examples for API Interactions
No preview available for this content.
Jan 26, 2024
Read MoreDiscussion 0
Please sign in to join the discussion.
No comments yet. Be the first to share your thoughts!