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
Related
I recently installed apache2 and Mysql on my RaspberryPi, I also setup FTP so I can edit my Files on my PC and upload them directly to the webserver.
If I now connect to my server vis it's IP-Address I can see the index.html, but as soon as I try to open a *.php file it shows the content of said file instead of interpreting it.
Are there any common mistakes that could make this happen?
Thanks for your help
This kind of errors mainly happen 3 reason
You may not be installed php
if you have installed php, you have not configured with apache
Check your php file having opening php tag <?php and closing php tag ?>
The same thing can happen if you have short php tags disabled. If it is disabled - all code that starts with <?..., <?=... will be printed on the screen just as simple text. Everything can be checked very easy: just create some php file and add <?php echo phpinfo() ?>. If browser will show php info - than problem is really in disabled short pho tags.
In that case you can simple enable that in php.ini with the directive short_open_tag=On (not recommended, however).
This is from php.ini file:
; This directive determines whether or not PHP will recognize code between
; <? and ?> 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 <?php and ?> 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://php.net/short-open-tag
short_open_tag = On
Your HTTP's response header should have "Content-Type:text/html". Have you checked that?
You don't have PHP configured to interpret php files within Apache or the PHP module is not known to Apache.
apt-get install libapache2-mod-php5
or
apt-get install php5
in apache.conf (or similiar) add line like:
LoadModule php5_module modules/libphp5.so
<FilesMatch "\.ph(p[2-6]?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
see http://www.php.net/manual/en/install.unix.apache2.php
Install php and any web server
http://www.apachefriends.org/en/xampp.html
download and install and goto C:/xampp/htdocs
make directory of your project and in browser type localhost/your_directory_name
I just installed XAMPP 1.8.1 and have restarted my computer, started running Apache and MySQL, and created a test file in a test folder in my htdocs directory under XAMPP.
When I go to xampp/index.php, their page comes up fine. But my test file only returns the actual characters in my PHP file in the "Response" tab in firebug, but a completely blank white screen in the window. The file is definitely .php extension - can anyone help?
The crazy thing is, I had this working 6 months ago just fine and have just gotten back to it on a new install.
I think you might be using short tag <? ?> or <?= ?> instead of <?php ?>.
Check your php.ini. It locates at \path\to\xampp\php\php.ini. The short_open_tag should be On.
; Allow the <? tag. Otherwise, only <?php and <script> tags are recognized.
; NOTE: Using short tags should be avoided when developing applications or
; libraries that are meant for redistribution, or deployment on PHP
; servers which are not under your control, because short tags may not
; be supported on the target server. For portable,redistributable code, be sure not to use short tags.
short_open_tag = On
I have an Apache server running PHP-5.3.0 for Windows. For the creation of pdf files, I need to activate the pre-bundled pdf library (referred here) in my php by editing the configuration file. How can I do this?
Or is there any other way to enable pdf creation?
Go to PHP's root directory > php.ini. Ctrl+F 'extension=php_pdflib.dll' and remove the semicolon (;) at the start of the line. Then restart Apache. If the semicolon isn't there, then it should already be activated. If there isn't any results from the Ctrl+F, it likely means you don't have it installed. You could try adding 'extension=php_pdflib.dll' (anywhere will do).
You can use a small file to test whether the library is loaded, just write in it:
<?php phpinfo();
Watch for php.ini in the output of this script, and add the following line to the file (you may need additional privileges to do that, right click your editor -> Run as Administrator):
extension=php_pdflib.dll
Restart apache, and check that pdf has been installed by checking the aforementioned phpinfo file.
Unless you're doing really advanced PDF stuff (and you need the non-free version of php-pdf for that), I can really recommend Prince XML. It converts XML and HTML into PDF and adds additional CSS properties, like page dimensions and numbers, PDF bookmarks and the like. Their documentation is better in demonstrating that than any of their marketing pages.
I solved it using TCPDF.. Its easy to handle. No need to edit php.ini.
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.
I took over a PHP project and I'm trying to get it running on my dev box. I'm a developer and not a sysadmin, so I'm having trouble getting it working.
The previous developer used .h files to include PHP. My current configuration is taking that .h file and including it without executing it. What do I need to look for in my apache config (or is it my php.ini)?
EDIT:
Something clicked when I read one of the comments below. The code is using ASP style tags "<?". I've turned the option on in php.ini and according to phpinfo(), it's enabled, but apache is still just including the code as text.
I just checked it and running the code with the full opening PHP tag "<?php" fixes the problem. Having said that, I'd still like it to work the other way.
I'm running the code on a Macbook with the latest versions available. PHP 5.2.6, postgresql 8.3 and apache 2.
The code works on the staging server, but I can't figure out what the difference it.
EDIT
Durrr...I didn't have short_open_tags enabled in php.ini.
Could the problem be that the .h file you are including just starts into php code without the opening "<?php" tag?
From include documentation:
When a file is included, parsing drops out of PHP mode and into HTML mode at the beginning of the target file, and resumes again at the end. For this reason, any code inside the target file which should be executed as PHP code must be enclosed within valid PHP start and end tags.
PHP is an interpreted language, so you can't 'include' a file without executing it. Remember that '.h' is just a file extension, so although the previous coder may have put PHP in a '.h' file, it's still just PHP.
More details on the problems you're running into would be helpful.
you can use a .htaccess file and add:
php_value auto_prepend_file /path/to/include-file.h
Edit
I've just read that .htaccess only works with the module version of php.
You should change them all to .php extensions. But, if you are going to leave them as .h, you change the mapping in Apache. It's Apache that runs the file through the proper interpreter, not PHP. The PHP engine will process anything passed to it.
include and require will execute the included file. If you are using readfile, it simply echoes the file without treating it as PHP code.
If the .h files are "missing" the <?php directive, then you may have to switch from include to something like:
eval( file_get_contents("file.h") );
Personally I try to avoid eval whenever I can, but sometimes there is just no choice.