PHP includes...
Moderator: General Moderators
PHP includes...
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
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
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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.
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.
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
<?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
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...
/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...
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
If you use file_exists() does it say the file exists? How about is_readable()?
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....
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>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.
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.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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.
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.
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.
<?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.
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.
<?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.
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).
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).