Web Browser shows nothing when I execute my php code - php

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

Related

Include not working after upgrade php 5.3.3 to 5.6.30

I'd like to upgrade the version of PHP I'm using for my website. I'm currently using 5.3.3 and have managed to install 5.6.30 (so I can run better PHP code to do cooler things!).
When I switch over to 5.6 the include files on my pages don't work at all. When I look at the source code it shows the PHP code for the include instead of the code the include file should show.
For example it shows this in the page source:
<? include ("../bobs-house/new_website_top.php");?>
None of the includes work so I doubt it has anything to do with their contents.
I've tried using absolute file paths but that doesn't work.
I'm using Plesk v12.0.18 on CentOS 6.8 - I'm note sure what else you'll need to know.
Thanks in advance,
Jon
It appears you have a trouble with the short tag configuration
If you don't want to change all of your code replacing <? ?> to <?php ?>, you can change php.ini in the line
short_open_tag=On
And restart Apache

Php code in .tpl files (no template-engine)

I'm using no template engine, but I have an index.php file, which requires my "index.tpl" file. So I can divide php and html code. In the index.tpl file I can use the php short-syntax and everything works fine... I have so say: worked. I had to reinstall my server (my SD-card of the PI was broken) and now this way doesn't work anymore. The php-code in the .tpl-files isn't executed anymore.
How do I have to configure my apache, that the code gets executed? Strangely I never had this problems in any installation before.
UPDATE:
I just tested: php code in .html-files doesn't work either.
Make sure that the PHP short opening tags <? ... ?> are enabled :
To achieve this, just set :
short_open_tag=On
In your php.ini file and then restart your Apache server.
Source

XAMPP not parsing PHP

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

Beginner Question PHP (ServerQuestion)

Hy!!
I just get a vserver running debian. I just installed apache and php. Now the server should support php.
i uploaded the file index.php:
<?
echo "Hallo";
?>
The problem is if i start a request to the site my browser wants to download a file.
Whats could be the problem?
THX
have you restarted apache after installing PHP?
/etc/init.d/apache2 restart
This could mean that the Mime extension of the File is not registered with the web server which means you will need to check if you have the PHP Interpreter installed as a extension/plugin in your server.
Try:
<?php
echo "Hallo";
The short_open_tags is disabled in may distributions by default. If you have to support legacy pages you can anable them in php.ini, if not then just use the above, your code will be more compatible.
Your server isn't set to parse PHP files before they are output.
Check out these pages:
http://www.phpbuilder.com/board/archive/index.php/t-7100332.html
http://www.petefreitag.com/item/516.cfm
If your page works if you changed that to the <?php tags, then vbence would be right, it could be as shanethehat says that you just need to restart apache if you've already made the change to php.ini, one of the joys of all these things working together you need to work through all the options to find out where these things fall down so you know where to start looking to fix it
(Found why it wasnt displaying, I hadnt put code round the php tags)

Setting for <? and <?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.

Categories