Setting for <? and <?php - php

I am running 5.2.14. Starting php code code using <? does not work. I must use <?php
For example:
Does not work:
<? phpinfo(); ?>
Does work:
<?php phpinfo(); ?>
Where can I change this setting so <? will work?

edit yout php.ini file, and set short_open_tag = On
you can view the php.ini's path by runing phpinfo(); function...
but, you can just write your scripts starting with <?php
Mike ;]

It is best not to use the short tag <? in place of the normal <?php. If you ever need to host on a server that doesn't support editing the PHP configuration, it is a pain to find and replace the short tags with the standard ones.
From http://php.net/manual/en/ini.core.php:
Tells PHP whether the short form (<?
?>) of PHP's open tag should be
allowed. If you want to use PHP in
combination with XML, you can disable
this option in order to use
inline. Otherwise, you can print it
with PHP, for example: <?php echo
'<?xml version="1.0"?>'; ?>. Also, if
disabled, you must use the long form
of the PHP open tag (<?php ?>).

Yeah as mishunika says change your php.ini file though be warned, if moving to another server later on it might not work. If you don't have access to the php.ini file on the other server you'll have to change them over to
<?php
Any reason you don't want to use the long tag?

I agree with everyone in regards to using short tags. You should for compatibility reasons stay away from short tags. However, there are situations which may call for it. For example, if you are trying to use a PHP script that someone else wrote that uses short tags, then you can either modify the code or enable short_open_tag.
If you do not have writable access to the php.ini file (shared hosting) you may be able to set the flag using the PHP function "ini_set". You can read up on the function here:
PHP ini_set
There are some flags and variables you cannot set with ini_set. I haven't personally tried to set the short_open_tag. Give it a shot.

Related

Web Browser shows nothing when I execute my php code

I'm starting to learn php, but at the beginning I came across with an error which I don't know how to solve it. I have installed wampserver 2.4 in my windows 7. When I tried to execute a simple file containing only an echo, nothing appeared neither an error.
What's the problem?
My code:
<?
echo "oi";
?>
In php.ini file you have no permission to use short tag
change it
from short_open_tag = Off
to short_open_tag = On
or use full tag
<?php //full php tag
echo "oi";
?>
The problem probably is that short open tag is not on.
Change it in php.ini
In the php.ini file you have to change is make sure that will be like that:
short_open_tag = On
Also, try to use <?php instead <?
Also you can do it by wamp server, click on the wamp icon, go to PHP-> PHP Extensions -> open short tags

PHP: <?= not working / Apache configuration issue?

I've ran into this issue before but don't remember what was causing it. I have a small app that uses the shorthand notation to print variables, <?=$myvar?>, but it doesn't seem to get parsed by the webserver?
Any ideas on what might be wrong here? It's a bit weird since everything else is working ok.
Thanks!
its a short open tag with an echo command (=). since php 5.4 its no longer marked as short open tag and therefore works even with php.ini setting short_open_tags set to off beginning with that version. for earlier versions it depends on that option.
more information:
http://php.net/manual/en/ini.core.php#ini.short-open-tag
you can check that option e.g. using $sot = ini_get('short_open_tags');
It may be turned off in the PHP configuration. Did you try adding this to your script?
<?php
phpinfo();
?>
Anyway, try to avoid short tags because they're good for nothing except creating a portability issue. :)
Not only check for the short_opened_tags but also be sure that AddHandler application/x-httpd-php .php is in your http.conf file. If its not there please add it and restart your apache server.

How can I get apache to interpret <? lines as php lines?

I'm inheriting some html/php code.
I've installed apache and php on my windows box. At first, things sort of worked until I realized that php.ini is not being sourced. When I changed the path to the ini file to somewhere other than the "Program Files (x86)" dir, the file is sourced, but the code I'm running stops working.
The code has a bunch of places that say <? foobar ?> instead of <?php foobar?>
I tried googling for '<?' vs '<?php', but it ignored the <? parts.
What configuration do I need telling apache that <? means php?
you have to set short_open_tag = On in php.ini. However due to conflicts with XML this is generally seen as a bad idea.
It doesn't look like the best idea. What about creating a script to process the files searching for strings containing "<?" without "php" in order to correct them? Using regular expressions it shouldn't be hard.

PHP - WAMP server

I have a problem with WAMP server (2.1); I have some php files that contain php statements between
<? statements ?>
and the browser don't interprets the code. If I use :
<?php statements ?>
everything works ok.
Any idea how to fix it. Thank you.
Whether you should or should not use short tags is debatable. I personally do not and I don’t recommend it. That being said — with WAMPServer 2 you can:
Click on the wampserver tray icon.
Go to PHP. Then PHP Settings
Click short open tag. (When it's on it will have a
checkmark next to it.)
Using the tray icon (lower right — next to the clock) is the easiest, least error prone way to make any changes in WAMPServer 2+.
As kieran said:
This is a good thread on why you shouldn't use short tags: Are PHP
short tags acceptable to use?
If you decided to used them, add in your php.ini:
short_open_tag=On
Documentation for php.ini directives
Be carefull, in a wamp installation, php.ini can be found at multiple locations:
wamp\bin\apache\Apache<version>\bin\php.ini
wamp\bin\php\php<version>\php.ini
Accessing the php.ini from the wamp menu (left click on wamp tray icon / php / php.ini) opens the php.ini of the current apache version.
This is a good thread on why you shouldn't use short tags: Are PHP short tags acceptable to use?
Don't use <? statements ?> - short tags are evil!
You can change it in the php.ini file but it even says in that file not to use them...
This directive determines whether or not PHP will recognize code
between tags as PHP source which should be processed as
such. It's been recommended for several years that you not use the
short tag "short cut" and instead to use the full tag
combination. With the wide spread use of XML and use of these tags
by other languages, the server can become easily confused and end up
parsing the wrong code in the wrong context. But because this short
cut has been a feature for such a long time, it's currently still ;
supported for backwards compatibility, but we recommend you don't use them. Default Value: On ; Development
Value: Off ; Production Value: Off ;
http://www.php.net/manual/en/ini.core.php#ini.short-open-tag

PHP Mailer Session Problem

We are trying to implement a mailer with an attachment upload option.
It's working great on two of the servers I've uploaded it to.
However, it does not seem to work on my localhost wamp server or even on a different server:
http://203.76.126.68/mailer/
Why am I seeing session values inside the text boxes?
Can anyone point out what seems to be the problem?
Any help would be appreciated.
Thanks!
Short Open Tags might be turned off. The easiest way to fix this is to just do a find and replace and change <?= into <?php echo.
http://php.net/manual/en/ini.core.php#ini.short-open-tag
You can also turn it on (might be possible in .htaccess) in php.ini.
Check if that script is actually processed by PHP.
If it is process by the PHP CGI binary, make sure short_open_tag is set to On. Those <?= ... ?> thingies only work with short_open_tag enabled.
you have shorttags off that's why you have to set it on in php ini or i think you can use the wamp menu and then setting and then turn on shorttags

Categories