PHP require... what is wrong?

pistuka

New Member
Messages
8
Reaction score
0
Points
0
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.
 

techairlines

x10 Flyer
Community Support
Messages
2,867
Reaction score
165
Points
63
If your pages are in the public_html directory, try using

PHP:
<?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).
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
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 ?
 

pistuka

New Member
Messages
8
Reaction score
0
Points
0
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.
 

pistuka

New Member
Messages
8
Reaction score
0
Points
0
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.
 

pistuka

New Member
Messages
8
Reaction score
0
Points
0
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.
 

as4s1n

New Member
Messages
174
Reaction score
4
Points
0
You don't get any error messages?

try a try/catch

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

techairlines

x10 Flyer
Community Support
Messages
2,867
Reaction score
165
Points
63
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:

pistuka

New Member
Messages
8
Reaction score
0
Points
0
I tried with semicolon - still not working. Tried try-catch version - not working.

But it seems to be that the problem is not access path nor permissions.

It's the
<?php
...
?>
block does not even get processed. I tried an only single line

<?php
print "a";
?>
and nothing happens.

I browsed my settings maybe php is disabled, but I could not find anything.

Any idea please?
 
Last edited:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
To have the PHP processor handle a file, it should have an extension of "php", not "html". If whatever tutorial or book you're studying doesn't mention this, find a new one. If you aren't learning from a tutorial or book, find one.
 

pistuka

New Member
Messages
8
Reaction score
0
Points
0
To have the PHP processor handle a file, it should have an extension of "php", not "html". If whatever tutorial or book you're studying doesn't mention this, find a new one. If you aren't learning from a tutorial or book, find one.

You can insert php scripts into your html page.
Starting with "<?php" tag, ending with "?>". If whatever tutorial or book you're studying doesn't mention this, find a new one.

Example:

<html>

<head>
<title>Example #1 TDavid's Very First PHP Script ever!</title>
</head>
<? print(Date("1 F d, Y")); ?>

<body>
</body>
</html>
 

pistuka

New Member
Messages
8
Reaction score
0
Points
0
To have the PHP processor handle a file, it should have an extension of "php", not "html". If whatever tutorial or book you're studying doesn't mention this, find a new one. If you aren't learning from a tutorial or book find one.

You can insert php scripts into your html page.
Starting with "<?php" tag, ending with "?>". If whatever tutorial or book you're studying doesn't mention this, find a new one.

Example:

<html>

<head>
<title>Example #1 TDavid's Very First PHP Script ever!</title>
</head>


<body><? print(Date("1 F d, Y")); ?>
</body>
</html>
 
Last edited:

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
You can insert php scripts into your html page.
Starting with "<?php" tag, ending with "?>". If whatever tutorial or book you're studying doesn't mention this, find a new one.

Example:

You can insert the tags, but as you have seen, and as you have been told by one of the most knowledgeable posters here, they are not processed under normal circumstances.

x10hosting does not parse .html files with PHP. Apparently your old host did. It is not standard.

Try listening to people who know.
 
Last edited:
Top