PHP includes...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
Alex-Grim
Forum Newbie
Posts: 17
Joined: Mon Dec 26, 2005 10:56 pm
Location: Hell's Gate

PHP includes...

Post by Alex-Grim »

Hey guys, i THINK i'm new here, but evidently i'm not (tried to register, it said the email already was registered, tried my normal uname + passwd, and sure enough, i was already a memeber. Funny, i just switched to linux, i wonder why i was here before...).

Anyway, i'm having problem with includes. I found my /etc/php.ini and changed my include directory to /var/www/html, but it still isn't including anything. Here's the code i'm trying to use:
<?php include 'ads/g_side.txt'; echo "vvvvvvvvvvvvvvvvvvvv";?>

"Vvvvvvvvvvvvvvvvvvvvv" prints out, but not the txt file (which was an html file, but i changed it to see if it was the problem).
Any clues?

thanx
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Often changes to php.ini require that the web server process be restarted. While you are in there, I'd suggest altering your error_reporting and display_errors settings to E_ALL and on, respectively, if they aren't already set in that fashion.
User avatar
Alex-Grim
Forum Newbie
Posts: 17
Joined: Mon Dec 26, 2005 10:56 pm
Location: Hell's Gate

Post by Alex-Grim »

I did restart the server twice with 'service httpd restart'. And with the error reporting, do i put that in my script or somehwere in my php.ini file? I will try it in the script first. Thanx.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

For development purposes, in the php.ini.

edit: forgot to add that you may want to take a look at the output of getcwd() and get_include_path() to see where php will be searching for your file.
User avatar
Alex-Grim
Forum Newbie
Posts: 17
Joined: Mon Dec 26, 2005 10:56 pm
Location: Hell's Gate

Post by Alex-Grim »

Yeah, i put this in the page and restarted the server just to be sure, and got nothing in return:
<?php error_reporting(E_ALL);?>

Now, in the php.ini, i noticed it had a weird syntax for the path to the includes, something like:
'.:/includes'
which i changed to:
'/var/www/html'

So, is that the wrong syntax?
Thanx
User avatar
Alex-Grim
Forum Newbie
Posts: 17
Joined: Mon Dec 26, 2005 10:56 pm
Location: Hell's Gate

Post by Alex-Grim »

Yeah, i tried the 'get_include_path()' and it returns '/var/www/html', but i didn't know about the getcwd(thanks), but it output the same directory (/var/www/html) since that is where it was being called from (index page). So that's why i'm stuck, lol, everything SEEMS right...
User avatar
Alex-Grim
Forum Newbie
Posts: 17
Joined: Mon Dec 26, 2005 10:56 pm
Location: Hell's Gate

Post by Alex-Grim »

Sorry, but meant to add that - like i previously mentioned - i am calling this include file from:
/var/www/html/index.kill (yes, i have it set up so that it runs that to php),
and the file i'm calling to include is located at:
/var/www/html/ads/g_side.txt

I am calling it with:
<?php include 'ads/g_side.txt'; ?>
but i've also tried:
<?php include './ads/g_side.txt'; ?>

And to make sure it's being parsed, i concatenate:
echo 'vvvvvvvvvvvvvvvvvvv';
And it outputs that properly, but not the include...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If you use file_exists() does it say the file exists? How about is_readable()?
User avatar
Alex-Grim
Forum Newbie
Posts: 17
Joined: Mon Dec 26, 2005 10:56 pm
Location: Hell's Gate

Post by Alex-Grim »

Well, it does exist, but it is NOT readable... not sure why? It's a .txt, php can handle that right? But i've tried it as both html and php too...
Here's the file's contents....

Code: Select all

<script type="text/javascript"><!--
google_ad_client = "pub-3862067914932046";
google_ad_width = 120;
google_ad_height = 240;
google_ad_format = "120x240_as";
google_ad_type = "text_image";
google_ad_channel = "";
google_color_border = "006600";
google_color_bg = "000000";
google_color_link = "00ff00";
google_color_text = "aaaaaa";
google_color_url = "00ff00";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
User avatar
Alex-Grim
Forum Newbie
Posts: 17
Joined: Mon Dec 26, 2005 10:56 pm
Location: Hell's Gate

Post by Alex-Grim »

Nevermind...
I took out all that code, and put 'ttttttttttttttttttttttttttttttttttttttttt' in there, and it works...
NOTE: You CANNOT have '<script> at the top of the file...

Thanx fayd, i learned a few new troubleshooting functions thanks to you.

BTW, it still says the file exists, but is NOT readable, but as long as it includes it anyways i'm happy.
--Edit--
clearstatcache will probably fix that.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I've not had a problem placing <script> at the beginning of files. Not having readability can signal a permissions problem.

PHP can include any file it can read. It will attempt to parse it for PHP code, so if it does contain any, it will be parsed. If you don't want PHP to parse the file, readfile() may be used, or file_get_contents(), depending on what you're attempting.
User avatar
Alex-Grim
Forum Newbie
Posts: 17
Joined: Mon Dec 26, 2005 10:56 pm
Location: Hell's Gate

Post by Alex-Grim »

Yeah, i'm in for a long night with this one, as it's still giving me problems:
<?php if ($_SERVER['HTTP_QUERY_STRING']){include '';echo'ddddddd';}else{include 'content/default.txt';echo'eeeee';}?>

That outputs 'eeeee' but not that NEW file's contents....
I have the directory permissions at 777 so that i don't have to be root to create new content, so i don't think it's that...

--Edit--
file_get_contents doesn't do it either, same result, and it looks like readfile only returns the length of the file.

In this particular case, i am only trying to read in html markup to dynamically change the content based upon querystring parameters.
User avatar
Alex-Grim
Forum Newbie
Posts: 17
Joined: Mon Dec 26, 2005 10:56 pm
Location: Hell's Gate

Post by Alex-Grim »

Wierd, i added this:
<?php if (is_readable('content/default.txt')){echo 'xxxxxxxxx<br/>xxxxxxxxxxxx<br/>xxxxxxxxx';}?>

And got 'xxxx' on 3 lines, but yet it still isn't including it... but it's saying that it DOES exist, and it IS readable...


----------Edit----------------------
Readfile worked, not sure why the others didn't, but that one did. I was re-reading about the function and found that i was wrong about it only returning content length. Thanx.
User avatar
Alex-Grim
Forum Newbie
Posts: 17
Joined: Mon Dec 26, 2005 10:56 pm
Location: Hell's Gate

Post by Alex-Grim »

Got it. When you right click in a directory and select 'new file' and start typing in that file, well, evidently to php that's different from create one with a text editor, because it doesn't give any problems for the files created by Gedit.

So i just <ctrl><shift><s>'d all the files i was working on, and saved them with a different name, and readfile'd them fine (though php.net says you're supposed to use get_file_contents).
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

i've got the feeling that the in your eyes 'mysterious' behaviour is caused by filesystem access rights...
Post Reply