idetinkin/php-curl-parser

Transform the curl command to the PHP Curl Object or Curl resource.

dev-master 2020-08-24 16:08 UTC

This package is auto-updated.

Last update: 2024-04-25 00:54:26 UTC


README

The simple way to generate a Curl object from the curl command intended for command line.

Example of usage

If you want to simulate user actions on a third party site (acceptably only if the user trusts your service, or you are your user):

  1. Open a web site where you want to simulate user actions
  2. Open DevTools by pressing Control+Shift+J
  3. Click the Network tab. The Network panel opens
  4. Click the Doc tab
  5. Refresh the page
  6. Right-click on the request and select Copy -> Copy as cURL
  7. Pass the text from clipboard to the PHP script

Example of the PHP script

$curlCommand = "curl 'https://www.google.com/?gws_rd=ssl' \
    -H 'authority: www.google.com' \
    -H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36' \
    --compressed";

$curl = (new \curlParser\Parser($curlCommand))->getCurlObject();
$html = $curl->exec();

Supported attributes

  • -H or --header
  • --compressedx