Discussion:
Changing User Agent for fopen
Gohaku
2003-12-04 15:36:10 UTC
Permalink
Hi everybody,
There are some pages I would like to extract links from but I can't
access the page using the following:
ini_set('php.user_agent', 'Mozilla/5.0');
$url = "http://www.google.com/search?q=php";
$fp = fopen($url,"r");
$buffer = fread($fp,1000000);
echo $buffer;
Also, what is the best number to use when allocating Buffer space for a
URL?
Is 1000000 too much?
Thanks.
-Gohaku
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
jon
2003-12-04 15:52:11 UTC
Permalink
You might want to look at curl as an alternative -- it gives you a lot
more flexibility than fopen.

-- jon

-------------------
jon roig
web developer
email: ***@trafficdesigns.com
phone: 888.230.7557


-----Original Message-----
From: Gohaku [mailto:***@earthlink.net]
Sent: Thursday, December 04, 2003 8:36 AM
To: php-***@lists.php.net
Subject: [PHP] Changing User Agent for fopen


Hi everybody,
There are some pages I would like to extract links from but I can't
access the page using the following:
ini_set('php.user_agent', 'Mozilla/5.0');
$url = "http://www.google.com/search?q=php";
$fp = fopen($url,"r");
$buffer = fread($fp,1000000);
echo $buffer;
Also, what is the best number to use when allocating Buffer space for a
URL?
Is 1000000 too much?
Thanks.
-Gohaku
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.544 / Virus Database: 338 - Release Date: 11/25/2003


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.544 / Virus Database: 338 - Release Date: 11/25/2003
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Gerard Samuel
2003-12-04 15:54:30 UTC
Permalink
Post by Gohaku
Hi everybody,
There are some pages I would like to extract links from but I can't
ini_set('php.user_agent', 'Mozilla/5.0');
This should work ->
header('User-Agent: Mozilla/5.0');
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Stuart
2003-12-05 13:10:01 UTC
Permalink
Post by Gohaku
There are some pages I would like to extract links from but I can't
ini_set('php.user_agent', 'Mozilla/5.0');
$url = "http://www.google.com/search?q=php";
$fp = fopen($url,"r");
$buffer = fread($fp,1000000);
echo $buffer;
1) The php.ini option is user_agent, not php.user_agent. Changing that
has the desired effect.

2) If you want to query google you're better off using the google SOAP
API - it's legal for a start. See the following for more info...

http://www.google.com/apis/
http://www.devshed.com/Server_Side/PHP/GoogleAPI/page1.html
Post by Gohaku
Also, what is the best number to use when allocating Buffer space for a
URL?
Is 1000000 too much?
Thanks.
-Gohaku
3) You're better off looping to get the full contents than trying to
'guess' how big the file will be. Try the following...

<?php
ini_set('user_agent', 'Mozilla/5.0');
$url = 'http://www.google.com/search?q=php';
$fp = fopen($url, "r");
while (!feof($fp))
{
$buffer = fread($fp, 1024);
echo $buffer;
}
?>
--
Stuart
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Nick Wilson
2003-12-05 14:36:58 UTC
Permalink
* and then Stuart declared....
Post by Stuart
2) If you want to query google you're better off using the google SOAP
API - it's legal for a start. See the following for more info...
http://www.google.com/apis/
http://www.devshed.com/Server_Side/PHP/GoogleAPI/page1.html
and
http://dietrich.ganx4.com/nusoap/index.php

An excellent SOAP tookit.
--
Nick W
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Stuart
2003-12-05 16:40:34 UTC
Permalink
Post by Nick Wilson
* and then Stuart declared....
Post by Stuart
2) If you want to query google you're better off using the google SOAP
API - it's legal for a start. See the following for more info...
http://www.google.com/apis/
http://www.devshed.com/Server_Side/PHP/GoogleAPI/page1.html
and
http://dietrich.ganx4.com/nusoap/index.php
An excellent SOAP tookit.
Indeed, as used in the DevShed article :)
--
Stuart
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Loading...