Jump to content

Why use <?php instead of <? ?


DeathRay2K

Recommended Posts

<? only works when thats enabled in the php.ini files, many ppl have this switched off, and if they use any scripts of you that contains <? it wont work, therefore its better to make everything with <?php to be sure noone gets trouble with it

Link to comment
Share on other sites

The XML preamble starts with <?. Many servers have short tags disabled so that PHP doesn't try to run XML or XHTML files that have a .php extension. In other words, a "valid" XHTML file starts off like this:

<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"		"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

That is from the W3C XHTML template. If you have PHP code in that file and save it as .php then PHP will try to execute the XML preamble at the top and you'll get an error, so some servers have short tags disabled. If you're trying to make your code portable then it's always best to use the long tags.

Link to comment
Share on other sites

It's not really a tag itself, it's just a shortcut for <? echo. It won't work if short tags are disabled. None of these tags are "dangerous", but there's an issue of portability if you choose to use short tags. Your applications will not run on some servers.

Link to comment
Share on other sites

Well it could be "dangerous" in the sense that if the PHP code isn't parsed by the server and outputted in the source that is sent to the client's browser, then they could go "view source" and may get potentially sensitive information such as database connection information.

Link to comment
Share on other sites

Well I would hope that when you upload the code you would notice that it's not running before any clients got to it. If you're putting broken applications online and not noticing they are broken then short tags aren't your only problem.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...