Click to See Complete Forum and Search --> : I know no PHP and I'm having an include problem..


vada
07-07-2007, 10:55 PM
Alright, as I said, I do not know ANY real PHP but I use includes on my websites so I do not have to edit every single page every time I add a link or edit something simple. The includes I guess work fine but I am having trouble with this...
(this is the ONLY PHP I have in the file)

<?php include("$p.txt");
if(empty($p)){include ("welcome.txt");} ?>

When there is no selected include the welcome.txt DOES appear but above it there is the error telling me the following:

Warning: main(.txt): failed to open stream: No such file or directory in /home/content/r/a/c/racetrailers/html/erin/index.php on line 85

Warning: main(.txt): failed to open stream: No such file or directory in /home/content/r/a/c/racetrailers/html/erin/index.php on line 85

Warning: main(): Failed opening '.txt' for inclusion (include_path='.:/usr/local/lib/php') in /home/content/r/a/c/racetrailers/html/erin/index.php on line 85

What needs to be changed or can anything be?

Thanks for your time. :D

pcthug
07-07-2007, 11:17 PM
Basically $p is empty. Where does $p get set? If I'm guessing correctly you have register_globals and your passing the $p via the query string.

If this is the case I'd suggest using something similar to


<?php

$pages = array(
'foo',
'bar',
'baz');

$page = in_array($_GET['p'], $pages) ? $_GET['p'] : 'welcome';

include "$page.txt";

vada
07-07-2007, 11:29 PM
Well I will try what you said but I have NO idea what any of that means and I highly doubt that the problem is as difficult as that? I am not using anything but a plain notepad document for any of this so whatever register_globals is I have no clue. The include works on every page where in the URL it says 3.php?p=(w/e) and there I guess p=whatever is the value. However, I'm trying to avoid having that .php?p=we on my index page so it can truly be an index page. I do not know if that makes any sense at all but that is the best I can explain it.

I have the page uploaded as index.php and that works but I need for someone to be able to type in the normal www.blah.com and be able to reach it without all that other junk... that is why I have the if there is no value for p then include this special txt document or whatever...that is how I understand it.

vada
07-08-2007, 12:10 AM
I have no idea what you are talking about...sorry.
I'm just trying to find a way to get my index.php?p=welcome page to show up without having to type up the ?p=welcome part so that someone can easily type in www.domainname.com without all that extra stuff. Is this possible? Is there another way to approach this other than PHP?

pcthug
07-08-2007, 03:18 AM
Ok, the code I posted previously will do exactly what you want. Here is a simpler (yet insecure) version


<?php

$page = !isset($_GET['p']) || empty($_GET['p']) ? 'welcome' : $_GET['p'];

include "$page.txt";


Now when you go to www.domainname.com you will be presented with the contents of welcome.txt

vada
07-08-2007, 02:44 PM
Oh! Thank-you! I'm soooo very sorry for doubting you. Thanks again!