+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 16
Like Tree2Likes

Thread: PHP require... what is wrong?

  1. #1
    pistuka is offline x10Hosting Member pistuka is an unknown quantity at this point
    Join Date
    Apr 2010
    Posts
    8

    PHP require... what is wrong?

    Hi Everyone,

    I am building a simple site of some pages consisting of text + some photos + menu on the right side.
    I have a file named menu.txt in /home/pistuka/public_html directory.

    In order to display the same menu on every page I want to load this txt file to be part of my html pages, displaying the menuitems. I use the php function require as it follows:

    some html tags here
    <?php
    require($DOCUMENT_ROOT . "menu.txt");
    ?>
    some more html tags here

    I also tried the following:

    some html tags here
    <?php
    require("/home/pistuka/public_html/menu.txt");
    ?>
    some more html tags here

    But it does not appear. Nothing appears where the menu should appear. I suppose that the problem is at permissions or access path.

    Please someone tell me what is wrong.
    Thank you.

    PS: All this had been working for a while on another web hosting service but I had to move to x10hosting.com.

  2. #2
    techairlines's Avatar
    techairlines is offline x10 Flyer techairlines has much to be proud oftechairlines has much to be proud of
    Join Date
    Jul 2009
    Location
    New York City
    Posts
    2,853

    Re: PHP require... what is wrong?

    If your pages are in the public_html directory, try using

    PHP Code:
    <?php
    require("menu.txt")
    ?>
    Make sure permissions are set properly so that your pages are able to access the menu.txt file (should be something around 755).
    Best regards,
    Brian Yang - TechAirlines


    How am I doing? Click the star button at the bottom left to rate this post. Thanks.
    Terms of Service | Account Portal | Wiki

  3. #3
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: PHP require... what is wrong?

    If PHP cannot load the file , require throws and error and you would see that.

    Got a URL we can look at?

    Care to post contents of menu.txt ?
    Nothing is always absolutely so.

  4. #4
    pistuka is offline x10Hosting Member pistuka is an unknown quantity at this point
    Join Date
    Apr 2010
    Posts
    8

    Re: PHP require... what is wrong?

    Thanks, I have tried. Still not working.

    After trying I displayed the source of my page. Between the HTML tags and text I can see the

    <?php
    require("menu.txt")
    ?>

    PHP code... Does this mean that the code was not even processed? Maybe PHP not supported?

    Thanks.

  5. #5
    pistuka is offline x10Hosting Member pistuka is an unknown quantity at this point
    Join Date
    Apr 2010
    Posts
    8

    Re: PHP require... what is wrong?

    Quote Originally Posted by descalzo View Post
    If PHP cannot load the file , require throws and error and you would see that.

    Got a URL we can look at?

    Care to post contents of menu.txt ?
    Hi, link to my page: http://pistuka.x10hosting.com/. The menu should appear on the right side.

    Contents of menu.txt:

    <h2>Temas tipicos</h2>
    <ul>
    <li><a href="index.html">Introduccion</a></li>
    <li><a href="seguridad.html">Seguridad, sobrevivencia</a></li>
    <li><a href="transporte.html">Transporte publico</a></li>
    <li><a href="restaurantes.html">Restaurantes, comidas t&iacute;picas *</a></li>
    <li><a href="monumentos.html">Monumentos principales</a></li>
    <li><a href="balnearios.html">Balnearios</a></li>
    <li><a href="mercados.html">Mercados, compras</a></li>
    <li><a href="fiesta.html">Ir de fiesta</a></li>
    <li><a href="hoteles.html">Hoteles recomendados</a></li>
    </ul>


    And that's all. Thanks again.

  6. #6
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: PHP require... what is wrong?

    Url?
    Nothing is always absolutely so.

  7. #7
    pistuka is offline x10Hosting Member pistuka is an unknown quantity at this point
    Join Date
    Apr 2010
    Posts
    8

    Re: PHP require... what is wrong?

    Quote Originally Posted by descalzo View Post
    Url?
    I posted URL and contents of menu.txt but the forum engine replied that my post will be published only after a moderator approved it.

    Maybe because of containing Url it seemed to be spam to the forum engine.

  8. #8
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: PHP require... what is wrong?

    I give up.
    Nothing is always absolutely so.

  9. #9
    as4s1n's Avatar
    as4s1n is offline x10 Sophmore as4s1n is an unknown quantity at this point
    Join Date
    Apr 2009
    Location
    Washington State
    Posts
    174

    Re: PHP require... what is wrong?

    You don't get any error messages?

    try a try/catch

    PHP Code:
    try {
          require(
    "menu.txt");
    } catch(
    Exception $e) {
         echo 
    $e->getMessage();

    Last edited by as4s1n; 04-21-2010 at 06:15 PM.
    There is no such thing as a "stupid question," there are only "stupid people" who don't ask them.

  10. #10
    techairlines's Avatar
    techairlines is offline x10 Flyer techairlines has much to be proud oftechairlines has much to be proud of
    Join Date
    Jul 2009
    Location
    New York City
    Posts
    2,853

    Re: PHP require... what is wrong?

    Quote Originally Posted by pistuka View Post
    Thanks, I have tried. Still not working.

    After trying I displayed the source of my page. Between the HTML tags and text I can see the

    <?php
    require("menu.txt")
    ?>

    PHP code... Does this mean that the code was not even processed? Maybe PHP not supported?

    Thanks.
    Oops sorry. I forgot to add the ending semicolon. Add a semicolon after the parentheses.
    Last edited by techairlines; 04-21-2010 at 11:40 PM.
    Best regards,
    Brian Yang - TechAirlines


    How am I doing? Click the star button at the bottom left to rate this post. Thanks.
    Terms of Service | Account Portal | Wiki

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. php ? include require
    By dharmil in forum Scripts & 3rd Party Apps
    Replies: 20
    Last Post: 08-27-2011, 07:32 PM
  2. Smarty( Fatal error: require() [function.require] )
    By AsianX in forum Scripts & 3rd Party Apps
    Replies: 1
    Last Post: 04-22-2009, 04:02 PM
  3. need help on function require
    By shawgsm in forum Programming Help
    Replies: 2
    Last Post: 02-04-2008, 09:45 AM
  4. PHP question regarding require()
    By idlehands in forum Scripts & 3rd Party Apps
    Replies: 0
    Last Post: 12-11-2007, 02:51 PM
  5. Require a bit of help getting Ads into Rash
    By kirbyss in forum Scripts & 3rd Party Apps
    Replies: 3
    Last Post: 10-26-2007, 11:48 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers