Page 1 of 2

Job - fix php "includes" on page

Posted: Wed Sep 14, 2005 1:40 pm
by davidx03
I don't know much of anything about php really if you visit my site here:
http://www.bp-grafix.net/sitebuilder/page.php?id=1

You'll see the error:
Warning: main(.html): failed to open stream: No such file or directory in /home/bpgrafix/public_html/sitebuilder/page.php on line 118

Warning: main(): Failed opening '.html' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/bpgrafix/public_html/sitebuilder/page.php on line 118

---

It's just simple php includes but it isn't working, I think the script is correct just the php on the server. Here is my servers phpinfo:
http://www.bp-grafix.net/sitebuilder/test.php

I made the page.php page a zip file so you can download it and see the php script here:
http://www.bp-grafix.net/sitebuilder/page.zip

If someone can fix this for me I'll pay $50 minimum, thanks. View my profile for contact methods.

Posted: Wed Sep 14, 2005 1:45 pm
by hawleyjr

Code: Select all

<?php
	if(phpversion() >= 4.2){
	 include($_SERVER[DOCUMENT_ROOT]."$id.html");
	} else {
	 include($DOCUMENT_ROOT."$id.html");
	}
?>
Should be:

Code: Select all

<?php
$id = $_GET['id'];
	if(phpversion() >= 4.2){
	 include($_SERVER['DOCUMENT_ROOT']."/$id.html");
	} else {
	 include($_SERVER['DOCUMENT_ROOT']."/$id.html");
	}
?>
Edit: If the files you are storing are in the same directory as page.php you can just use: include("$id.html"); Also, you have a huge security risk here. you should do some validation on the $_GET['id'] var before including the file.

Posted: Wed Sep 14, 2005 2:17 pm
by davidx03
hawleyjr thankyou for the suggestion but

Code: Select all

<?php 
$id = $_GET['id']; 
    if(phpversion() >= 4.2){ 
     include($_SERVER['DOCUMENT_ROOT']."/$id.html"); 
    } else { 
     include($_SERVER['DOCUMENT_ROOT']."/$id.html"); 
    } 
?>
doesn't work.

also include("$id.html"); doesn't work, i think theres something going on with the php on the server thats why i posted the location to the phpinfo.

Posted: Wed Sep 14, 2005 2:18 pm
by hawleyjr
Is there a file on your server in the same directory as that page named 1.html

Posted: Wed Sep 14, 2005 2:21 pm
by hawleyjr
lol, I answered my own question. Yes there is.

*The page we are talking about is probably not suitable for most work networks....


Your warning is main(.html) not main(1.html)

For testing reasons try this:

Code: Select all

include("1.html"); 

and

  include($_SERVER['DOCUMENT_ROOT']."/1.html");

Posted: Wed Sep 14, 2005 2:32 pm
by davidx03

Code: Select all

include("1.html");

works

Code: Select all

include($_SERVER['DOCUMENT_ROOT']."/1.html");

gives error:
Warning: main(/home/bpgrafix/public_html/1.html): failed to open stream: No such file or directory in /home/bpgrafix/public_html/sitebuilder/page.php on line 116

Warning: main(): Failed opening '/home/bpgrafix/public_html/1.html' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/bpgrafix/public_html/sitebuilder/page.php on line 116

Posted: Wed Sep 14, 2005 2:34 pm
by hawleyjr
What does this produce:

Code: Select all

echo '<HR><PRE>'; print_r($_GET); echo '</PRE>';

Posted: Wed Sep 14, 2005 2:36 pm
by davidx03
when i add

Code: Select all

echo '<HR><PRE>'; print_r($_GET); echo '</PRE>';
this comes up:
--------------------------------------------------------------------------------

Array
(
)

Posted: Wed Sep 14, 2005 2:38 pm
by hawleyjr
Should be:

Code: Select all

Array
(
    [id] => 1
)
Thats what I'm seeing:

http://www.bp-grafix.net/sitebuilder/page.php?id=1

Posted: Wed Sep 14, 2005 2:50 pm
by davidx03
yea thats right thats what i see i was just looking at page.php.

so is there a way to change to script to this works for me? and show the 1.html page?

Posted: Wed Sep 14, 2005 2:54 pm
by hawleyjr
Replace all of your PHP code with the following:

Code: Select all

if(file_exists($_GET['id'] . '.html')) {
   include($_GET['id'] . '.html';
}else{
echo 'File ' . $_GET['id'] .'.html  Does Not Exist';
}

Posted: Wed Sep 14, 2005 3:02 pm
by davidx03
i did that im gettin error:
Parse error: parse error, unexpected ';' in /home/bpgrafix/public_html/sitebuilder/page.php on line 118

link 118 is:

Code: Select all

include($_GET['id'] . '.html';
i removed the ';' but then says:
Parse error: parse error, unexpected '}' in /home/bpgrafix/public_html/sitebuilder/page.php on line 118

Posted: Wed Sep 14, 2005 3:02 pm
by hawleyjr

Code: Select all

include($_GET['id'] . '.html');

Posted: Wed Sep 14, 2005 3:08 pm
by davidx03
IT WORKED!!! THANKS BRO!!! FINALLY! i will pay you, tell me method you prefer. i got paypal

Posted: Wed Sep 14, 2005 3:10 pm
by hawleyjr
Glad it works, my paypal act is:

xxxxxx