Page 1 of 1

Have problem parsing php

Posted: Tue Jan 24, 2006 9:27 am
by sniper
feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hi everyone

I'm new here and need some help. I'm trying to use some php include codes in my html pages.

And this is what I have:

In the .htaccess

Code: Select all

AddType text/html .php .html
AddHandler server-parsed .html
Options All -Indexes
<Files ".ht*">
order allow,deny
</Files>

In my html pages, I have these:

Code: Select all

<?php
define(NUMBER_SHOW, 2);
$text = glob('http://www.domain.com/randomarticle/*.txt');
shuffle($text);
for ($i = 0; $i < NUMBER_SHOW; ++$i) {
    include($text[$i]);
}
?>
NOTE: This is a php code that is suppose to read into a folder and pulls out random files to be displayed.

Code: Select all

<?php include('http://www.domain.com/adsense.php'); ?>
NOTE: This is a php include tag.

I don't think there's any problem with the htaccess because there was no error generated, meaning it was able to read the php lines.

However, nothing gets displayed, be it the random files, or the adsense code.

I've no idea what went wrong. Can someone please advise me?

TQ

- Darren


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Tue Jan 24, 2006 9:45 am
by Bill H
I think the include in the "for" loop needs quotes

Code: Select all

include("$text[$i]");
and I would try double quotes rather than single quotes in the adsense include statement.

(Are you sure the files are there?)

Posted: Tue Jan 24, 2006 10:23 am
by Christopher
It should be:

Code: Select all

define('NUMBER_SHOW', 2);

Posted: Tue Jan 24, 2006 7:59 pm
by sniper
Hi Feyd

My boo-boo. Sorry for not using the code tags and thanks for pointing it out to me.

Hi Bill and arborint

I changed according to your suggestions and it still didn't work. So what I did was edit the .htaccess file to this:

Code: Select all

AddHandler application/x-httpd-php .php .html
Now, the Adsense include DO WORK! Thanks.

However, for the random code, it generated an error.

This is the code I'm using now:

Code: Select all

<?php
define('NUMBER_SHOW', 2);
$text = glob('http://www.domain.com/randomarticle/*.txt');
shuffle($text);
for ($i = 0; $i < NUMBER_SHOW; ++$i) {
    include("$text[$i]");
}
?>
In my randomarticle folder, I have put in 4 test files: 1.txt 2.txt 3.txt and 4.txt

None of them was pulled out and got this error instead:
Warning: main(): Failed opening '' for inclusion (include_path='.:/usr/lib/php/:/usr/share/pear/') in /home/domains/domain.com/web/index.html on line 28

Warning: main(): Failed opening '' for inclusion (include_path='.:/usr/lib/php/:/usr/share/pear/') in /home/domains/domain.com/web/index.html on line 28
Any idea what happened now? My hair is getting less and less due from the scratching of my scalp :roll:

TQ.

- Darren

Posted: Tue Jan 24, 2006 8:09 pm
by Jenk
it tried to include a file with the path and name of '' (i.e. no name)

Which of course cannot be possible :)

This means that at some point, $text[$i] has no value. Probably because you can't glob over http :)

Posted: Tue Jan 24, 2006 8:10 pm
by John Cartwright
try changing

++$i

to

$i++

Posted: Tue Jan 24, 2006 8:43 pm
by Bill H
It's not finding the files. The pathname must be in error, or the files do not exist in the specified folder.

Jenk had it right. From the php manual for glob():
Note: This function will not work on remote files as the file to be examined must be accessible via the servers filesystem.