error77
asked on
PHP and Browser User Agent
Hi all,
How can I change the browser user agent but code please?
How can I change the browser user agent but code please?
ASKER
I've added this to me php page
It's still telling me I'm using Firefox when the code above should set it to IE 9
Any ideas on why it;s not working please?
<?php
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; MSIE 9.0; WIndows NT 9.0; en-US))');
?>
It's still telling me I'm using Firefox when the code above should set it to IE 9
Any ideas on why it;s not working please?
ASKER
Anyone please?
Hi,
Use firefox then download addon called: User Agent
you can change user agent of your browser to anything you
want to pretend, example:
iphone,
IE8,
IE9,
Safari,
googlebot
msnbot
hope that help.
Use firefox then download addon called: User Agent
you can change user agent of your browser to anything you
want to pretend, example:
iphone,
IE8,
IE9,
Safari,
googlebot
msnbot
hope that help.
ASKER
I've got that addon but this I need to do it via the web page as it's for a simulator.
Hi error77,
It would depending on whether you are trying to access the web page itself pretending to be a different web browser (user agent) or whether your PHP code retrieves content from a remote resource and you want this process to appear as a different browser (user agent).
I believe if you want to open a page in your web browser (Firefox) but have the web site believe you are using a different user agent then boon86's answer above would be correct. The alternative would be in your code where you check what user agent the request came from simply override this with the desired user agent for testing. Another alternative would be to use the browser with the desired user agent.
If, however you would like your PHP code to request content from a remote resource impersonating a specific user agent then the answer from RIk-Legger is correct presuming your are using CURL to retrieve the data. The alternative if you are using fopen() etc would be to use:
Please note I haven't tested the above suggestions however they have what I've come up with from Google results.
I hope these suggestions help, my apologies if they do not.
Cheers
Matt
It would depending on whether you are trying to access the web page itself pretending to be a different web browser (user agent) or whether your PHP code retrieves content from a remote resource and you want this process to appear as a different browser (user agent).
I believe if you want to open a page in your web browser (Firefox) but have the web site believe you are using a different user agent then boon86's answer above would be correct. The alternative would be in your code where you check what user agent the request came from simply override this with the desired user agent for testing. Another alternative would be to use the browser with the desired user agent.
If, however you would like your PHP code to request content from a remote resource impersonating a specific user agent then the answer from RIk-Legger is correct presuming your are using CURL to retrieve the data. The alternative if you are using fopen() etc would be to use:
ini_set('user_agent', 'Mozilla/5.0 (Windows; U; MSIE 9.0; WIndows NT 9.0; en-US)');
Please note I haven't tested the above suggestions however they have what I've come up with from Google results.
I hope these suggestions help, my apologies if they do not.
Cheers
Matt
ASKER
Sorry but none of the examples work...
At the top of my page I have:
Then unde that I have:
and It's returning:
Mozilla/5.0 (Windows NT 6.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2
and not Internet Explorer ... why is it not working please?
At the top of my page I have:
ini_set('user_agent', 'Mozilla/5.0 (Windows; U; MSIE 9.0; WIndows NT 9.0; en-US)');
Then unde that I have:
echo $_SERVER['HTTP_USER_AGENT'];
and It's returning:
Mozilla/5.0 (Windows NT 6.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2
and not Internet Explorer ... why is it not working please?
<?php
$url = 'http://www.example.com/a-large-file.zip';
$path = '/path/to/a-large-file.zip ';
$fp = fopen($path, 'w');
$ch = curl_init($url);
$ch = curl_setopt($ch,CURLOPT_US ERAGENT,'M ozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt($ch, CURLOPT_FILE, $fp);
$data = curl_exec($ch);
curl_close($ch);
fclose($fp);
?>
$url = 'http://www.example.com/a-large-file.zip';
$path = '/path/to/a-large-file.zip
$fp = fopen($path, 'w');
$ch = curl_init($url);
$ch = curl_setopt($ch,CURLOPT_US
curl_setopt($ch, CURLOPT_FILE, $fp);
$data = curl_exec($ch);
curl_close($ch);
fclose($fp);
?>
correction:
<?php
$url = 'http://www.example.com/a-large-file.zip';
$path = '/path/to/a-large-file.zip';
$fp = fopen($path, 'w');
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt($ch, CURLOPT_FILE, $fp);
$data = curl_exec($ch);
curl_close($ch);
fclose($fp);
?>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
For curl it is:
Open in new window