Problem
You're troubleshooting an issue involving a specific user on your Drupal site. You can reproduce the issue by requesting pages while logged in as that user, but would like to use the command-line tool, cURL, to gather additional diagnostic information about these requests.
Solution
You can use cURL to make authenticated HTTP requests to your site on behalf of this user for troubleshooting and testing purposes by sending a session cookie that corresponds to this user's account with your cURL request.
Before we begin:
Please note that if someone has access to your session ID, they'll be able to log into the site as your user until that session is deleted or expires. For this reason, you should be extremely careful when sharing or publishing session identifier information, as it could be used to gain unauthorized access to the Drupal user account on your site.
To make an authenticated cURL request for a Drupal user, follow these steps:
- First, retrieve the cookie for an active session corresponding to the user's account. You can use command-line to generate a cookie from a one-time login link, or of you're already logged-in as this user in your browser, you can get it from your browser's cookie management page.
- Next, make a cURL request, using cURL's "-b" (cookie string) option to insert the cookie you retrieved in step one:
curl -sLIXGET http://www.example.com -b 'SESSb109ff8067496f95bcf6f677440ae7e0=3ZttTadIF4heaJiq9QIvjGEOrK6B-d4MJVWngRqgFjQ;'
Note: replace "SESSb109ff8067496f95bcf6f677440ae7e0=3ZttTadIF4heaJiq9QIvjGEOrK6B-d4MJVWngRqgFjQ;" in the code above with the value of the cookie you retrieved in step 1.