1. Go to this page and download the library: Download hamaadraza/php-impersonate library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
hamaadraza / php-impersonate example snippets
Raza\PHPImpersonate\PHPImpersonate;
// Simple GET request
$response = PHPImpersonate::get('https://example.com');
echo $response->body();
// POST request with data
$response = PHPImpersonate::post('https://example.com/api', [
'username' => 'johndoe',
'email' => '[email protected]'
]);
// Check the response
if ($response->isSuccess()) {
$data = $response->json();
echo "User created with ID: " . $data['id'];
} else {
echo "Error: " . $response->status();
}
// GET request with optional headers and timeout
PHPImpersonate::get(string $url, array $headers = [], int $timeout = 30): Response
// POST request with optional data, headers and timeout
PHPImpersonate::post(string $url, ?array $data = null, array $headers = [], int $timeout = 30): Response
// PUT request with optional data, headers and timeout
PHPImpersonate::put(string $url, ?array $data = null, array $headers = [], int $timeout = 30): Response
// PATCH request with optional data, headers and timeout
PHPImpersonate::patch(string $url, ?array $data = null, array $headers = [], int $timeout = 30): Response
// DELETE request with optional headers and timeout
PHPImpersonate::delete(string $url, array $headers = [], int $timeout = 30): Response
// HEAD request with optional headers and timeout
PHPImpersonate::head(string $url, array $headers = [], int $timeout = 30): Response
// Get the HTTP status code
$response->status(): int
// Get the response body as string
$response->body(): string
// Check if the response was successful (status code 200-299)
$response->isSuccess(): bool
// Parse the response body as JSON (throws \JsonException on failure)
$response->json(bool $associative = true, int $depth = 512, int $flags = 0): mixed
// Check whether a header is present (case-insensitive)
$response->hasHeader(string $name): bool
// Get the first value of a header (case-insensitive), or $default when absent
$response->header(string $name, ?string $default = null): ?string
// Get ALL values of a header — use this for Set-Cookie and other repeatable headers
$response->headerAll(string $name): string[]
// Get all headers as a map of name → list of values
$response->headers(): array<string, string[]>
// Serialise to a plain array
$response->toArray(): array
// Dump response details to a string (for logging)
$response->dump(): string
// Print response details and return self (for debugging)
$response->debug(): Response
$contentType = $response->header('Content-Type'); // 'application/json'
$etag = $response->header('ETag', 'none'); // fallback to 'none'
if ($response->hasHeader('X-Rate-Limit-Remaining')) {
$remaining = $response->header('X-Rate-Limit-Remaining');
}
$allHeaders = $response->headers();
// [
// 'Content-Type' => ['application/json'],
// 'Set-Cookie' => ['sessionid=abc; Path=/; HttpOnly', 'csrftoken=xyz; Path=/'],
// 'Cache-Control'=> ['no-cache, no-store'],
// ]
foreach ($response->headers() as $name => $values) {
// $values is always an array, even for single-value headers
foreach ($values as $value) {
echo "$name: $value\n";
}
}
// Create a client that mimics Firefox
$client = new PHPImpersonate('firefox135');
$response = $client->sendGet('https://example.com');
// Set a 5-second timeout for this request
$response = PHPImpersonate::get('https://example.com', [], 5);
// Or when creating a client instance
$client = new PHPImpersonate('chrome107', 10); // 10-second timeout
// This will be sent as form data
$response = PHPImpersonate::post('https://example.com/api', [
'username' => 'johndoe',
'email' => '[email protected]'
]);
// Explicitly specify form data
$response = PHPImpersonate::post('https://example.com/api',
[
'username' => 'johndoe',
'email' => '[email protected]'
],
['Content-Type' => 'application/x-www-form-urlencoded']
);