PDA

View Full Version : PHP 'virtual ( )' giving error



Musikpro
28 Oct 2009, 05:00 PM
Hello,
I'm trying to use this to include a navigation bar on each of my pages.

<?php virtual('/nav.php'); ?>

However, whenever I try to view the page, it gives me an error, saying the function 'virtual()' is not defined.

So, I tried using 'include ()', and 'require_once()' but those too, aren't working...

to resolve the issue, I edited my nav.php file to just this:

<a href="/egerg.com">ergre</a>
<a href="/dfbd.com">dffbd</a>
<a href="/nyrh.com">rhrttr</a>


Still no luck....


Any suggestions would be greatly appreciated! Thanks!

Alan
28 Oct 2009, 06:56 PM
The virtual function is for apache sub requests. Just ignore it, you don't need it for this.

Your problem is your path. You have it set as "/nav.php". The forward slash implies the root directory of the system (I am assuming you are using a linux system), you will need to enter the absolute path or a relative path based on your current working directory.

"nav.php" or "./nav.php" will include the file from the current directory
"../nav.php" will include the file from the parent directory
"includes/nav.php" will include the file from the includes directory (which is located in the current directory)


<?php include('nav.php'); ?>

Also just to note that you have /dfbd.com links in your html above too... this is fine, as the / will imply the document root, which is the root directory relative to the host. While the link may be wrong, it is still valid.

http://www.example.com/dir1/dir2/dir3/index.html
a link to /dfbd.com will point to http://www.example.com/dfbd.com