not using full url
I'll try to describe this quickly. It's a php problem but it may have a simple html solution. I am establishing a variable in php on a primary page before calling an include file that will make use of the variable. This worked in my tests as the variable (ie. $test = "this is a test") was able to be printed from the other file.
But when I changed the include from just the file name in the same folder "test.php" to the full url "http://www.mysite.com/test.php", everything fails!
In my site, files are not all in the same folders so I need to find other ways I can call write the name of a file but without using it's full url? ../ may work. Does ../subfolder/file.php mean 'go to the top/main folder then work down again'? Any other methods? Is there a function in php that will stick the domain part in for you?
Just looking for work around suggestions.
Thanks.
Suzanne posted this at 17:27 — 21st December 2002.
She has: 5,507 posts
Joined: Feb 2000
../ will work without issue.
Other solutions are to set it up to read the path instead of the directory (relative path works?).
Dean (textism.com) had an interesting solution for his /refer/ script (see his site for details, and that code for more details).
fifeclub posted this at 04:09 — 22nd December 2002.
He has: 688 posts
Joined: Feb 2001
../ didn't work either. It spits out:
Warning: Failed opening '../header.php' for inclusion (include_path='') in ......
So far I know that including "header.php" will work. Using the full url will not create an error but the variable value will not carry thru to the included file. And Using ../ creates complete failure to even include the second page.
Any other ways?
Busy posted this at 06:09 — 22nd December 2002.
He has: 6,151 posts
Joined: May 2001
if ../ didnt work, try ../../ or even ../../foldername/
it all depends where the folders are and from where your starting from. example using a folder 2 back, 1 over is different if the calling files is in a upper directory than the lower one
Take a quick peek at [url=http://ezhtml.net/ezgraphics.html]here[/ur] for a directory tree example (third way down)
zollet posted this at 08:08 — 22nd December 2002.
He has: 1,016 posts
Joined: May 2002
/ = root directory (in PHP it's the server's root dir, but in HTML it's your domain's root dir)
./ = same directory
../ = One directory back
../../ = Two directories back
If you can't get it to work, then write us the FULL URL where your PHP script is, and also where is the file you're trying to include. This way it will be a lot easier for us to help you.
mairving posted this at 12:44 — 22nd December 2002.
They have: 2,256 posts
Joined: Feb 2001
Try using this:
<?php
include(\"$DOCUMENT_ROOT/test.php\");
?>
This will bring up the file to your public_html directory which would translate to http://yoursite.com/test.php
Mark Irving
I have a mind like a steel trap; it is rusty and illegal in 47 states
Suzanne posted this at 16:10 — 22nd December 2002.
She has: 5,507 posts
Joined: Feb 2000
Right, and Dean's solution was to make $DOCUMENT_ROOT a smaller variable for multiple uses.
mairving posted this at 02:28 — 23rd December 2002.
They have: 2,256 posts
Joined: Feb 2001
Yeah, I guess if I would have clicked on that link and looked around. Using $DOCUMENT_ROOT is a quick and dirty approach. A better solution generally is creating at least two variables. One that is the Root or whichever directory you want to be root and another variable for the system path (i.e. /home/username/directory). The second variable is useful for calling stuff that is in directories under the www directory which means that they won't show up over the web. A good place to stick usernames and passwords for databases.
Mark Irving
I have a mind like a steel trap; it is rusty and illegal in 47 states
Suzanne posted this at 02:43 — 23rd December 2002.
She has: 5,507 posts
Joined: Feb 2000
heh, I meant for fifeclub to look around.
fifeclub posted this at 04:17 — 23rd December 2002.
He has: 688 posts
Joined: Feb 2001
Thanks everybody. What I ended up doing was taking everybody's suggestions and a ton of examples from php.net and I tested all of them. Out of 12 testpages, I got 3 methods to work (call the other page and properly pass the variable to that other page). One way was using the ../ but I found that it could be dependant on how many folders down you were so that left two ways:
1) include("$DOCUMENT_ROOT/includes/header.php");
(and a 'require' version of this document_root method)
2) include "/home/mikesus/public_html/includes/header.php";
(which is just using the full path name)
One final question though. An alternate 'cousin' of the document_root method worked but used "require" instead of "include".
( require($DOCUMENT_ROOT . "/includes/header2.php"); )
Is there an advantage/disadvantage to using require instead of include?
Renegade posted this at 06:43 — 23rd December 2002.
He has: 3,022 posts
Joined: Oct 2002
yeah, i've been wondering that my self, I usually use the require instead if include - I just didn't want to make a new thread about it...
Abhishek Reddy posted this at 07:18 — 23rd December 2002.
He has: 3,348 posts
Joined: Jul 2001
fifeclub posted this at 16:23 — 23rd December 2002.
He has: 688 posts
Joined: Feb 2001
Last update from me on this subject. I started putting the DOCUMENT_ROOT method of calling my header on every page. It worked fine everywhere until I got to my photo album area ("Gallery"). For some unknown reason DOCUMENT_ROOT won't work here, but the 'full path' method does. So that seems to be the best solution for avoiding errors. (I guess)
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.