PDA

View Full Version : Question about PHP script to access ODP



LastActionHero
May 22nd, 2001, 11:35
I use a script called phod.php3 to access the Open Directory Project, when i run it it gives me the following error



Warning: fopen("http://dmoz.org/","r") - Bad file descriptor in /web/sites/64/merazone/www.merazone.f2s.com/phod/phod.php3 on line 159
error: could not open the url: http://dmoz.org/


As far as i know the syntax of fopen is correct. Also, I'am on f2s servers.

Click here to run script (http://www.merazone.f2s.com/phod/phod.php3)

[Edited by lastactionhero on 05-22-2001 at 12:03 PM]

ashben
May 22nd, 2001, 11:53
This could be weird but try: fopen("http://www.dmoz.org/","r") instead of fopen("http://dmoz.org/","r")

BTW, Do let us know if it solves the problem as I'm curious myself.

LastActionHero
May 22nd, 2001, 12:09
Nope, doesn't work, same error

lucifer
May 22nd, 2001, 13:33
is php running as a server module?

if so the manual says there can be probs with fopen

ashben
May 22nd, 2001, 14:24
I just ran a test script, $file = fopen("http://dmoz.org/", "r") works for me. Try checking on what lucifer mentioned. Also checkout the fopen documentation (http://www.php.net/manual/en/function.fopen.php). See if you can find something there.

LastActionHero
May 22nd, 2001, 23:50
Originally posted by lucifer
is php running as a server module?

if so the manual says there can be probs with fopen

From f2s servers


Is PHP running in SAFE MODE?
Yes. The PHP engine is compiled as a safe mode enabled Apache module. This makes it execute PHP scripts extremely quickly and safely. If the safe mode is too restrictive for your requirements, eg: you want to create a file upload script, then the php cgi engine can be used instead.

To run the slower cgi version of PHP your php file should end in .cgi and include at the top of the file the line:

#!/usr/bin/php


I guess it is running as a server module. I tried doing the CGI thingy, but still the same error

LastActionHero
May 22nd, 2001, 23:55
PHP fopen() documentation


If you are experiencing problems with reading and writing to files and you're using the server module version of PHP, remember to make sure that the files and directories you're using are accessible to the server process

How do i do that?

lucifer
May 23rd, 2001, 09:00
you could try

popen()

or

file()[need to rewrite your code]

doesn't seem to have this prob?

LastActionHero
May 23rd, 2001, 10:00
Finally!
I use popen(), the error has disapperared, but the output (http://www.merazone.f2s.com/phod/phod.php3) is not what it is supposed to be.

Note: the script is in debug mode, that is why it is printing all the info.

BTW if I were to use file() what changes do I have to make?

Woofcat
May 23rd, 2001, 10:05
Here's the old-fashioned way to do it...


$file=fsockopen("dmoz.org",80);
fputs($file,"GET / HTTP/1.1\r\n");
fputs($file,"Host: dmoz.org\r\n");
fputs($file,"Connection: close\r\n");
fputs($file,"User-Agent: Whatever\r\n\r\n");

You can then read from $file just like any other file...

lucifer
May 23rd, 2001, 10:26
Originally posted by lastactionhero
BTW if I were to use file() what changes do I have to make?

$myarray = file(....);

$myarray now has the files contents

$myarray[0] - 1st line
$myarray[1] - 2nd etc

jrap
May 23rd, 2001, 16:05
If you would rather have the contents from dmoz.org all inside the same variable, rather than in an array, just use:

$dmoz = implode("",file('http://www.dmoz.org'));

hope that helps

LastActionHero
May 24th, 2001, 01:55
A common question asked by f2s.com members is when to upgrade to the
global hosting series? (read: paid service) Here are some key guidelines to consider when
choosing to upgrade:


* You require top level domain hosting (eg: www.yourname.com)
* You need the best performance and stability
* You'd like access to priority telephone support
* Your website makes external connections or contains zip/mp3 files

So i guess the free hosting account doesn't support outside connections. But what I don't understand is how come popen() worked partly.
Can anyone please re-code the script using file(). I don't know how to code in PHP
Source code (http://imexis.com/phod.php3.txt)

lucifer
May 24th, 2001, 11:39
try removing


$fp = fopen("$requesturl", "r");
if(!$fp) {
echo "error: could not open the url: $requesturl<br>\n";
} else {
//fputs($fp,"$requesturl");
$line = "";
while(!feof($fp)) {
$line .= fgets($fp,256);
}
fclose($fp);

and putting instead

$line = implode("",file('http://www.dmoz.org'));

this has no error checking!!