homepage Welcome to WebmasterWorld Guest from 54.167.75.155
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
My member display list shows error in index.php
Scotty13




msg:4440579
 5:46 pm on Apr 13, 2012 (gmt 0)

If I pull up http://example.com/


In index.php...

</div>

<p> <?php print "$TKTedMemberDisplayList"; ?>

<div style="width:728px; height:827px; border: #999 thin solid; overflow:auto;"><?php print "$announcerDisplayList"; ?>

</div>

I get this one error in between a table and some pictures that show on my home page.

Notice: Undefined variable: TKTedMemberDisplayList in /home/*******/public_html/index.php on line 89 (should show members picture)

I use TKTedMemberDisplayList in other php pages and no problem.

However; If I pull up http://example.com/root/index.php The error is not there and the
TKTedMemberDisplayList shows members pictures.

Thanks in advance
Scott

[edited by: eelixduppy at 5:50 pm (utc) on Apr 13, 2012]
[edit reason] switched to example.com [/edit]

 

eelixduppy




msg:4440583
 5:52 pm on Apr 13, 2012 (gmt 0)

From what I can see, /index.php and /root/index.php are two different files. Can you tell me why I should believe otherwise?

Scotty13




msg:4440605
 6:52 pm on Apr 13, 2012 (gmt 0)

How did I get /index.php and /root/index.php from two diff files?

My index.php is located in my root folder.

eelixduppy




msg:4440613
 7:20 pm on Apr 13, 2012 (gmt 0)

As far as your web server is concerned, unless you have something going on behind the scene that I cannot see/am not aware of, these are two different locations...

There is a directory that your web server will recognize as the document root, let's say on your box it is this: /var/www

If you place a file here called index.php, it will have the absolute path on your box as this:

/var/www/index.php

And be accessible via a browser at www.example.com/index.php

Now, let's say you create a directory, root, and place a file, index.php in it.

file is at: /var/www/root/index.php

and is accessible via a brower as www.example.com/root/index.php

So, unless you have some magic happening behind the scenes that is rewriting your url, they are referencing two different files. This will explain why you are getting different results.

Scotty13




msg:4441090
 6:18 pm on Apr 15, 2012 (gmt 0)

I'm using FileZilla to FTP my web pages under /public_html then /root. Some pages have root and some don’t. My web hosting company says, its better if I move my folders and files in to this location… /home/user/public_html. It sounds like too much work.

Thanks, Scott

eelixduppy




msg:4441125
 8:54 pm on Apr 15, 2012 (gmt 0)

So does this mean you have two different versions of the file then, as I said above?

Scotty13




msg:4441607
 7:06 pm on Apr 16, 2012 (gmt 0)

Heres my website with index.php http://www.example.com/index.php

Heres my website with root/index.php
http://www.example.com/root/index.php
* This one shows 2 diff pictures in my memebers section. This one is correct. But why doesnt it show the two diff images on http://www.example.com?

[edited by: eelixduppy at 8:07 pm (utc) on Apr 16, 2012]

eelixduppy




msg:4441636
 8:10 pm on Apr 16, 2012 (gmt 0)

Please do not post links to your personal website; this is not allowed -- See Forum Charter [webmasterworld.com]


Back to your question --

You are not providing enough information for me to help you. Also, you still have not answered my question. Without some insight as to how your code is writing the URIs for the images, I will not be able to help you.

rocknbil




msg:4442087
 5:38 pm on Apr 17, 2012 (gmt 0)

It sounds like too much work.


Yet, you don't realize what everyone is telling you - you've actually made it too much work by creating this folder "root."

I can't even fully extract the cause of the problem from your posts, but I can tell you what is wrong with a near mathematical certainty, because it's the same problem most PHP coders exhibit - even many experienced ones. This is going to be a path issue, and it's going to be because you're using relative links, as in "relative to where this file is."

First, take their advice and get RID of that "root" folder. Just drag everything out of it and in the root of your domain. Someone somewhere told you to "put files in the root directory." So you (or someone) created a folder named "root" and put some stuff in there. That is not what it means.

Root describes your domain's root, the root from where your domain tree begins, and it's different in different contexts. It's **really** important you understand this difference or you're always going to struggle with missing images, includes that don't include, and all kinds of other crap that you won't get because you're thinking "relatively."

The root URL/URI is the root of your domain when called from the web. It's simply /, or the fully qualified URL: http://www.example.com.
The file system root is a completely different animal. Yes, it is the root of your domain, but it's the computers' path to your domain root. You can see whatever this is, at any time, by running phpinfo() or doing this.

echo $_SERVER['DOCUMENT_ROOT'];

Using your example, this is /home/example.com/public_html. (using your domain or user name.) This is not a URL/URL, this is your domain's file system root.

Why is this important? Most PHP code you will see here, and in all the code you'll scrape off the web, does s**t like this: (and it IS! SORRY!)

include('includes/file.php');
include('../includes/file.php');
include('../../../../includes/file.php');
<img src="img.jpg">
<img src="images/img.jpg">
<img src="../images/img.jpg">
<img src="../../../images/img.jpg">

Though it's particularly rampant in PHP, this insanity poisons CSS and Javascript as well:

background: url(../images/bg.jpg);

Note these carefully, we'll use the same examples later. What do all these have in common? The rely on relative paths, meaning, "Wherever I'm at now, step up or down to these directories and find this file." You can squeak along using this method, but the problem with it is that if something moves, you have to go back and modify all these instances, and you're constantly calculating "where you want to be from where I am now".

That's insane.

Complicate this once more: Many PHP coders treat PHP includes as URL's or URI's. They are not the same. PHP uses the file system path to include files, while URI's (images, other pages from a browser, whatever) use actual URI/URL's. Why do they do this?

Because it works one time, and they've no reason to believe it won't work forever. Which, as you're discovering, throws you into a tailspin when it doesn't.

In your case, You probably have the exact same file and have to figure out where that file is from the /root directory, then figure out where it is from the actual domain root. So if you have

/root/images/myfile.jpg

and then from /root/index.php,
<img src="images/myfile.jpg">

No problem. It finds it. But if you have the same img code in the index.php at the actual domain root, of course it won't find it. It's in the /root/images/directory and this code

<img src="images/myfile.jpg">

is not descending into the "root" directory.

Now, don't run off to fix this by putting "root" in front of the "images" in the img src of domain root copy of index.php. That would be a patch that would eventually resurface in some other page or project. Here is a permanent fix.

Here is what you do: Locate all "web reference paths" and change them to this:

<img src="/img.jpg">
<img src="/images/img.jpg">
<img src="/images/img.jpg">
<img src="/images/img.jpg"> <!-- note that this is now exactly the same as the first two examples! -->

What does this do? It says "DOESN'T MATTER where I am now. Start at the domain root and follow this path."

For all PHP includes, do this.
include($_SERVER['DOCUMENT_ROOT'] . '/includes/file.php');
include($_SERVER['DOCUMENT_ROOT'] . '/includes/file.php');
include($_SERVER['DOCUMENT_ROOT'] . '/includes/file.php'); // Look at that, they are all the same!

This does the same thing, but form the file system path. "Start at the file system root of this domain and field this file."

Trust me, DO the work, get rid of that root folder, adopt this policy and this problem will go away forever.

Scotty13




msg:4442186
 9:47 pm on Apr 17, 2012 (gmt 0)

ATTN RocknBill - your a saint. I will give do this in the next few days and let you know how I did.

I've been following some tutorials online and that I was taught to build a root & script folder. I'm new to all this and just trying to build a social network website.

Thanks again,
Scott

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved