开发者

PHP included functions not working in firefox 5

I have 2 files:

create.php:

<html>
<body>
<?php
require("Test.php");
hello();
echo "does this work?";
?>
</body>
</html>

and Test.php:

<?php
function hello(){
    echo "hello";
}
?>

But when I open create.php, nothing prints (not even "does this work?". If I call hello() from Test.php it works fine. That is, it doesn't seem to be executing code after the include. What am I doing wrong?

edit: the code seems to work fine in my IE 8 install, but not in my FF 5 install (which, admittedly, has 开发者_StackOverflowway to many addons).

edit again: the issue was that the page cache needed to be refreshed. There was never a problem. The code works. sorry, all.


Do yourself a favour and turn on error reporting. Place the following code at the beginning of create.php and let us know the error message(s) you receive.

<?php

ini_set('display_errors', 'on');
error_reporting(E_ALL);
require_once('Test.php');

?>

My guess is that it is a path issue.


First of all, you do not need the html tags in your PHP-File. Second: you need to execute your function. Now you only defined it. Try

Test.php

<?php
function hello(){
    echo "hello";
}
hello();
?>

And make sure that both files are in the same directory.


use dirname(FILE) instead of a stright include

eg

if i have a dir

/var/www/html/include

and test.php resides in includes and your script is in html then use dirname(__FILE__).'/includes/test.php

if you need to go back in a dir the use dirname(dirname(__FILE__))

depending on how many levels.

it also makes it dynamic so command line and browser will always fin the file


Try the code below for create.php

<?php
require('Test.php');
?>
<html><body>
<?php 
hello(); 
echo 'does this work?';
?>
</body>
</html> 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜