Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Require problem

Status
Not open for further replies.

Qwark

Programmer
Sep 26, 2000
59
0
0
NL
I have two files

- File1 menu.php:
<?php
require(&quot;?>

and some html and php...

- File2 menulink.php
<?php
echo(&quot;BlaBla&quot;);
$menulink1 = &quot;index.php?pagina=1&quot;;
$menulink2 = &quot;index.php?pagina=2&quot;;
$menulink3 = &quot;index.php?pagina=3&quot;;
$menulink4 = &quot;index.php?pagina=4&quot;;
$menulink5 = &quot;index.php?pagina=5&quot;;
$menulink6 = &quot;index.php?pagina=6&quot;;
?>

The file menu.php let me see BlaBla and then some other things. What i have made. But i can not use the variable from menulink.php in my menu.php script. When i put the variable direct in the file menu.php. It does work correctly. But I won't do that.

What is my problem, is there anything I'am doing wrong???

Qwark
 
Well, if require does not work, then try include, or include_once.

These are also control structures of PHP (like echo) and you do not need parentheses around the string.

If that does not work, define only variables in the file that you are include'ing and see if that works.

Hope this helps.

-Vic vic cherubini
krs-one@cnunited.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash
====
 
Before i have post this message I have also try include, include_once en require_once. Of course I have try to put an echo in in File2, and... that is working correctly. That's why i post this message. But thanks, for your advise.
I am doing something wrong but I don't know what!!!

But thanks for your Tip.

Qwark
 
Well if your require is like this in your code:
[tt]
require(&quot;[/tt]

Then you have an extra semi-colon there that doesn't need to be there.

Take the one out before the end parantheses.

If that doesn't work, try taking out that and see what that does.

Hope this helps.

-Vic vic cherubini
krs-one@cnunited.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash
====
 
Vic Cherubini found your problem with the last statement:

If you use an include() or a require() on a page with an &quot; path, then what you are getting is the output from that server *after* it has been parsed. Even if it is the same server, using an http:// path means that the require() function is acting like a web browser and fetching that page from the web. So what actually gets received by your &quot;menu.php&quot; page is:

BlaBla

and nothing else, since the other PHP code hs no output.

There are two things you can do:

1. If &quot;menulink.php&quot; is on the same server as &quot;menu.php&quot;, then just reference it with a local file path, instead of a web URL. Something like:

Code:
require(&quot;/home/httpd/htdocs/standaard/menulink.php&quot;);

2. If this is a remote page, then you need to be a little more creative. The first idea is to simply let your remote &quot;menulink.php&quot; page handle the creation of your link variables AND the output to the browser, so all you are receiving in menu.php is flat text:

- File2 menulink.php
Code:
<?php
 echo(&quot;BlaBla&quot;);
 $menuLink1 = &quot;index.php?pagina=1&quot;;
 $menuLink2 = &quot;index.php?pagina=2&quot;;
 $menuLink3 = &quot;index.php?pagina=3&quot;;
 $menuLink4 = &quot;index.php?pagina=4&quot;;
 $menuLink5 = &quot;index.php?pagina=5&quot;;
 $menuLink6 = &quot;index.php?pagina=6&quot;;

echo &quot;<a href=\&quot;$menulink1\&quot;>Menu One</a>&quot;;
etc...
?>

The other method (which you have to think carefully about) is to remove the <?php and ?> from menulink.php, so it is just flat text, then use

Code:
fopen(&quot;[URL unfurl="true"]http://www.boerenpagina.nl/standaard/menulink.php&quot;);[/URL]

Along with fgets, etc... (see
To open the file remotely and make it a string variable. Then you just eval() that string variable, to have it evaluate as PHP code on the other side. This is probably more trouble than its worth, and if there is any database connection or password info in menulink.php, then that is now visible to the browser, if someone happens to know it's location.
 
Thank you all for the help. I think I can solve the problem now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top