Job - fix php "includes" on page

Looking to hire a PHP developer for a paid position? Looking for a paid PHP job? Want to post your resume? Let the job hunt begin...

Moderator: General Moderators

davidx03
Forum Newbie
Posts: 8
Joined: Wed Sep 14, 2005 1:25 pm
Contact:

Job - fix php "includes" on page

Post 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.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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.
davidx03
Forum Newbie
Posts: 8
Joined: Wed Sep 14, 2005 1:25 pm
Contact:

Post 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.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Is there a file on your server in the same directory as that page named 1.html
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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");
davidx03
Forum Newbie
Posts: 8
Joined: Wed Sep 14, 2005 1:25 pm
Contact:

Post 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
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

What does this produce:

Code: Select all

echo '<HR><PRE>'; print_r($_GET); echo '</PRE>';
davidx03
Forum Newbie
Posts: 8
Joined: Wed Sep 14, 2005 1:25 pm
Contact:

Post by davidx03 »

when i add

Code: Select all

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

Array
(
)
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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
davidx03
Forum Newbie
Posts: 8
Joined: Wed Sep 14, 2005 1:25 pm
Contact:

Post 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?
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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';
}
davidx03
Forum Newbie
Posts: 8
Joined: Wed Sep 14, 2005 1:25 pm
Contact:

Post 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
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Code: Select all

include($_GET['id'] . '.html');
davidx03
Forum Newbie
Posts: 8
Joined: Wed Sep 14, 2005 1:25 pm
Contact:

Post by davidx03 »

IT WORKED!!! THANKS BRO!!! FINALLY! i will pay you, tell me method you prefer. i got paypal
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Glad it works, my paypal act is:

xxxxxx
Last edited by hawleyjr on Sun Jan 22, 2006 9:05 am, edited 1 time in total.
Post Reply