Last active
September 18, 2024 04:18
-
-
Save vyspiansky/82f4b1ef6fcff160047d to your computer and use it in GitHub Desktop.
PHP: set user agent using file_get_contents()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$options = array('http' => array('user_agent' => 'custom user agent string')); | |
$context = stream_context_create($options); | |
$response = file_get_contents('http://domain/path/to/uri', false, $context); |
This was helpful to me. Thanks!
Or set it globally
ini_set('user_agent', 'SomeBrowser v42.0.4711');
$response = file_get_contents('http://domain/path/to/uri');
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works like a charm!!! 🥰