开发者

Help needed in PHP include function!

While including a php file (eg: include'filename.php';), is it necessary that the source file (filename.php) has starti开发者_如何学Gong and ending php tags in it?


No, it's not necessary.

It is important to know, though, that when you include a file, the interpreter starts in HTML mode, just like in your initial script. So if you want to include PHP code (not literal output), you need a starting PHP tag.

The closing tag is optional: when the interpreter has stepped through the entire included script and returns to the parent script, it goes back into PHP mode. I recommend you never use the closing PHP tag at the end of your scripts; it can lead to strange bugs (the dreaded 'headers already sent' message).


No, it is not necessary to include <?php ?>tags. This is because the PHP parser just outputs the unchanged file contents if there are no tags which indicate the need for parsing PHP code.

It would be not a good practice though, because php files without php code are not recommended. If you have PHP code in your file, the tags are mandatory.


No there is no need to add php tag at the starting and end of your source filename . you have write include inside php tag i.e.

<?php include('filename.php'); ?>


is it necessary that the source file (filename.php) has starting and ending php tags in it?

Depends. If you want to include PHP script, it is necessary. If you want to include other type of file (not a PHP script) such as javascript/xml/text, then it is not necessary.


php tags are not required. But if you don't use them, you'll have security and confidentiality issues. Someone can get the sourcecode of the file (config stuff, database access, passwords, ...)!!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜