$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
return [
'security_key' => env('NMI_SECURITY_KEY', 'your-security-key-here'),
];In your .env file, add:
Aug 14, 2024
Read More Tutorial
python
Creating a Simple REST API with Flask
- Create a new item:
curl -X POST -H "Content-Type: application/json" -d '{"name": "Item 4", "price": 250}' http://127.0.0.1:5000/api/itemsAug 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!