PHP & Proxy

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

PHP & Proxy

Post by n00b Saibot »

How should I configure the php.ini so that I can access outside pages via a proxy installed in the network. If now i try to access outside addresses ex.

Code: Select all

print file_get_contents('http://www.google.co.in');
it says
Warning: file_get_contents(): php_network_getaddresses: gethostbyname failed in c:\web\anurag\PHP_Utilities\SearchInfo.php on line 9
I tried to look through every setting/directive in the php.ini but I don't pass by any such configuration option :(
Is there any such setting :?:
siefkencp
Forum Commoner
Posts: 69
Joined: Thu Dec 16, 2004 8:50 am

Post by siefkencp »

Have you tried using include?
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

siefkencp wrote:Have you tried using include?
8O What do you mean :?:
Bennettman
Forum Contributor
Posts: 130
Joined: Sat Jun 15, 2002 3:58 pm

Post by Bennettman »

When you include an outside page, it should get the code you usually see in the browser (i.e. the final code).

You could do the following to get the page into a variable:

Code: Select all

<?php

ob_start();
include 'http://www.google.co.in';
$content = ob_get_contents();
ob_end_clean();

?>
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

the problem is that php (actually, libdns or whatever your ip stack uses for hostname resolving) can't resolve the ip that belongs to the hostname.

what you could do is use an external dns server.. (add it to /etc/resolv.conf or read a windows manual :))
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

timvw wrote:the problem is that php (actually, libdns or whatever your ip stack uses for hostname resolving) can't resolve the ip that belongs to the hostname.

what you could do is use an external dns server.. (add it to /etc/resolv.conf or read a windows manual )
OK, Thanks for rep. but I have following:
OS: Win 98
Server: Apache 2.0
MySQL 4.sumthing

So all that libdns & /etc/resolv.conf goes tangent to my head.(not really but isn't really of that use to me :) ) OK, and now how will Windows Manual help in solving PHP's prob. After all I can connect to Google using IE. But the problem is that to access the net using PHP, it has to know the proxy settings. How to set it is what i am asking :(
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

it appears you can pass in a proxy variable (php5)

http://docs.php.net/en/wrappers.html

but at first sight it's not clear how to do it exactly..
Post Reply