Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
php include playing with my head
Old 09-09-2008, 04:57 PM php include playing with my head
Defies a Status

Posts: 2,071
Name: carl
Location: UK
Trades: 0
I thought I had this sus'ed but obviously not

I have an include on my site that my host did for me when i first put my new site up (which coincided with changing hosts)

The existing one is

Code:
<? include($_SERVER['DOCUMENT_ROOT'].'/asset/file.php'); ?>
I have been reading up on php and intend to use includes for all my links and other stuff as I rekon this will be easier, I thought I had them all figured out but ohh no, that would be way toooo easy

Everything I have read suggests this should work
or this
Code:
 
<?php include ("/asset/file.php"); ?>
I have tried chainging the " to ' as I read somewhere that can help (god only knows why, by god I mean some php guru )

I could copy what has already been done but I need to know exactly whats going on so I can confidently work stuff through.

I have googled all sorts of stuff and read a few dozen pages but cant find what I need.

Can ANYBODY please explain why the top include works and the others dont as everything I have read suggests the others should work fine.

I get the following errors when I use the last 2 incudes

Code:
Warning: include(/asset/file.php) [function.include]: failed to open stream: No such file or directory in /home/finan132/public_html/buy-to-let.html on line 103
 
Warning: include() [function.include]: Failed opening '/asset/file.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/finan132/public_html/buy-to-let.html on line 103
the /asset/file.php doesn;t exist, just using it as an example
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
bakerc is offline
Reply With Quote
View Public Profile Visit bakerc's homepage!
 
 
Register now for full access!
Old 09-09-2008, 05:43 PM Re: php include playing with my head
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
It's a file path problem, as you likely understood it.
Include can be made out of URL, but it must be enabled on the server, which is rare with shared host because it opens the door wide to XSS.

I'd recommend you to forget it.
Including URL, as fast as I know, is like including the html result of the php file, not the functions it contains.
So, if it's just a header or a link bar, it's ok, but not if you have classes, object, variables or function that you need to work with.

When you do an include, the server looks in several places. At first, the current position of the calling file in the filesystem tree is probed. If the including file is not found, then it will look in every places listed into the include_path configuration directive.

By the way, using single or double quotes don't make any differences for the PHP engine, except that in single quotes, the $something is not evaluated to a variable value, so it's a bit faster (but so neglectible that you can consider it's the same)

What your host did for you at first, was to reference your web site root directory (the $_SERVER['DOCUMENT_ROOT'] variable) as the prefix of the include path.
This will allow point to the server path of your web site root folder, making it easy to include the same file all the time, regardless of your position into your site arborescence.

What can cause your error now can be:
1) The file realy isn't there
2) The file is there, but the filename is not spelled correctly
3) The file is there, but the user who runs the php process (usually nobody, or apache) has no access to that specific path. A directory could be marked "not readable" for him. It happens often when you upload something via ftp (which use your specific user account) and when php try to access it (with the apache system account), the path is not allowed to be accessible by the group or the user apache.

To check if PHP as access to the file, try to adapt this PHP manual example to you:
PHP Code:
  <?php
$dir 
"/etc/php5/";  //customize here for the path to the folder containing your include, not the file to include

// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
    if (
$dh opendir($dir)) {
        while ((
$file readdir($dh)) !== false) {
            echo 
"filename: $file : filetype: " filetype($dir $file) . "\n";
        }
        
closedir($dh);
    }
}
?>
This will allow you to see what the php engine is able to access.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 09-09-2008, 05:59 PM Re: php include playing with my head
Defies a Status

Posts: 2,071
Name: carl
Location: UK
Trades: 0
Hi Trippy,

I listened to the ducky: Awsome

I wasn't sure if it was a permissions problem or a file path problem, although I figured it had to be one or the other.

When you say about the file being accessible, or php not being accessable, I would think it must be or ($_SERVER['DOCUMENT_ROOT'] wouldn't work would it? (which it does)

I take on baord your point about shared hosting which I understand. And I even clicked with the ($_SERVER['DOCUMENT_ROOT'] which is cool.

Thanks for your help.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Last edited by bakerc; 09-09-2008 at 06:02 PM..
bakerc is offline
Reply With Quote
View Public Profile Visit bakerc's homepage!
 
Old 09-09-2008, 06:58 PM Re: php include playing with my head
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Good, but please, spare the penguins...
The toasts are too hot for them, they prefer ice.

Penguins on the rock...
This, is tasty...

But just, excuse the froggy, but I did not understood your last comment.
Did you suceeded to get it running ?
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 09-09-2008, 07:12 PM Re: php include playing with my head
Defies a Status

Posts: 2,071
Name: carl
Location: UK
Trades: 0
Yes mate.

Well kinda...Not tried it with the links but the ($_SERVER['DOCUMENT_ROOT'] will work for the links as its already working for a form on my site. I will just change the path to the file containing the links - need to learn how to make the current page show as class=current automatically though which I am currently looking into - nothing is ever as straightforward as you would like it to be, getting there slowly.

Got a couple of php/mysql books and a few JS/Ajax books, and am going to go through each one (eventually) - its my new hobby, learning stuff (well not new but what the heck)

I didn't go through the books for an answer to the above as I wasn't sure what the problem was - cant look up the answer to a solution if ya dont know the question. But I am sure I will cover this stuff in more detail as I work through the books (one at a time)
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Last edited by bakerc; 09-09-2008 at 07:14 PM..
bakerc is offline
Reply With Quote
View Public Profile Visit bakerc's homepage!
 
Old 09-09-2008, 07:33 PM Re: php include playing with my head
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Good !
Quote:
I didn't go through the books for an answer to the above as I wasn't sure what the problem was - cant look up the answer to a solution if ya dont know the question. But I am sure I will cover this stuff in more detail as I work through the books (one at a time)
Yeah, I know how it feel.
Well, if anything pops again, just ask.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 09-10-2008, 10:59 AM Re: php include playing with my head
Defies a Status

Posts: 2,071
Name: carl
Location: UK
Trades: 0
I am a little confused now.

the include <?php include ("/asset/file.php"); ?> works for a links include page but not for the form?

Surely if it works for one it should work for the other?
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
bakerc is offline
Reply With Quote
View Public Profile Visit bakerc's homepage!
 
Old 09-10-2008, 12:03 PM Re: php include playing with my head
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
No, you are mixing up my comment (but I may had explained it better).

When you use ("/asset/file.php"), php try to open that file from the root of the server, not from the root of your web site.
But, as it try every location in the include_path, it might find it in those.

I was saying that when you include an url, in that case, it's like including the html generated by this file alone, when you access it with your browser.
Thus not importing the functions, classes or variables declared in it.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 09-10-2008, 12:20 PM Re: php include playing with my head
VirtuosiMedia's Avatar
Web Design Made Simple

Posts: 1,228
Trades: 0
Without testing to double check, if I remember right, I think if you were to use ("asset/file.php"), without the leading forward slash, it would make it relative to the loading page (provided that the loading page itself isn't an include).

A general tip for error checking...Google the error that comes up, minus the parts specific to your site, and you should usually be able to find a solution for most errors.
__________________
Want new web resources every day? - Follow me on
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 09-10-2008, 12:32 PM Re: php include playing with my head
Defies a Status

Posts: 2,071
Name: carl
Location: UK
Trades: 0
Thanks VM. I have tried it with and without the leading / with no success.

I have tried googling it (without my specific info) but couldn't find anything useful, there is plenty of information on
Code:
($_SERVER['DOCUMENT_ROOT']
but none that I can find to explain whay the relative path works on my links include but doesn't work for my form include and they are both held in the same file which is why I cant figure out whats going on.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
bakerc is offline
Reply With Quote
View Public Profile Visit bakerc's homepage!
 
Reply     « Reply to php include playing with my head
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.63534 seconds with 12 queries