Jump to content
xisto Community
chilipie

Tutorial: PHP Includes

Recommended Posts

I recently had some problem with includes. So here it is, if you know solution lemme know... Problem: If you have one php file in your public_html/ folder, called index.php, and in that index.php you include another file which is in public_html/directory/file.php - and in that included file "file.php" there is another inclusion of public_html/directory2/file2.php how can you manage to work it out... ?It gets me lots of errors, and I end with solution that it can't be done, because if I include something in some file in root directory (e.q. index.php) script will stay executed in that directory (hipoteticly) and if I include file which has line of code in it self include("../directory2/file2.php"); what it really does it goes directory back beyond public_html and finds nothing... - complicated huh :rolleyes: ? and I cannot change the code of that file.php because Im using it in another file and that file is in folder public_html/directory/ so that file needs that ".." part of code in include...How to solve this complication? any suggestion for different programming...?

Share this post


Link to post
Share on other sites

Hmm... maybe use absolute URLs? Instead of using relative urls like "../directory/index.html" you could use "http://forums.xisto.com/no_longer_exists/; in your embedded file (in this case, file.php) so that you won't have to worry about the script staying in the first file and not budging.Not a very elegant solution, but it might work if you only have a few files with this problem.

Share this post


Link to post
Share on other sites

Hmm... maybe use absolute URLs? Instead of using relative urls like "../directory/index.html" you could use "http://forums.xisto.com/no_longer_exists/; in your embedded file (in this case, file.php) so that you won't have to worry about the script staying in the first file and not budging.

Not a very elegant solution, but it might work if you only have a few files with this problem.

<{POST_SNAPBACK}>

Ii works in something like:

<html>

  <head>

      <title>Include Sample</title>

  </head>

  <body>

    <?php

            include("header.php");

      ?>

      <table width="95%" cellspacing="15" cellpadding="5" border="0">

        <tr>

            <td valign="top" width="120">

              <?php

              include("menu.php")

              ?>

            </td>

            <td valign="top">

  <?php

switch ($_GET['c']) {

    case '1':

    include("content" . $_GET['c'] . ".php");

        break;

    case '2':

    include("../www/file2/content" . $_GET['c'] . ".php");

        break;

    case '3':

        include("../www/file3/content" . $_GET['c'] . ".php");

        break;

    default:

        include('content1.php');

  break;

}

?>

            </td></tr></table>

 

      <?php

            include("footer.php");

      ?>

  </body>

</html>

The $_GET['c'] comes from:

<p align="center" style="font:bold 1em sans-serif;color:#000099">

  <a href="index.php?c=1">Home</a><br>

  <a href="index.php?c=2">Reality</a><br>

  <a href="index.php?c=3">Mision</a><br>

</p>

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.