I have a php-file which includes another html-file:
<? virtual("../top.html");?>
The problem is that any code before this include compiles and runs well, after - nothing. There aren't any errors etc. After commenting this line, everything works.
Code was written under local computer with ArchLinux + LAMP. Now I have ubuntu 10.04 with the same configuration.
What could it be?
You might try changing top.html to top.phtml and using require_once.
<?php require_once('../top.phtml'); ?>
If you just want to pass some html from a file into your output, you could also use:
<?php echo file_get_contents('../top.html'); ?>
That way, you stay independent of the underlying webserver and you make sure, that no php code that may be in the html is being executed.
However if you wish something in there to be executed, you can use require_once() as stated by Jeremy.
Can you check error log of the Apache?
Also, you should use
<?php virtual("../top.html");?>
if your php.ini has short_open_tag = Off.
Related
MCVE:
<?php
echo "testing!";
?>
Screenshot from accessing this script in Chrome:
Screenshot from running this script via the PHP command-line:
What's weird is that it hasn't always been this way. Everything was working perfectly yesterday, but ever since today, it's been doing this for whatever reason. Did I screw something up within the config of my Apache accidentally or something? Using XAMPP with PHP v7.3.8.
Wow, good catch KIKO Software! After checking the encoding of the file in Notepad++... I realized that it, for some reason, was set to "UCS-2 LE BOM". I changed it to "UTF-8" and now everything is working properly. Thank you!
If I use a code like this:
<?php
echo 'Text';
include("Class/MyClass.php");
echo 'Text';
?>
This code only returns one 'Text'. (The one before the include)
I don't get an error (error reporting on), and the code works on my local XAMPP.
Debian 6.0 / PHP 5.3.3-7+squeeze15
Apologize in advance - it's not the answer but just wild guesses.
"Class/MyClass.php" (or any file it includes) contains somewhere exit() or die() calls that depend on configuration.
Try setting error_reporting(E_ALL) and ini_set('display_errors', '1') right before including.
I recently set up an AWS EC2 instance and installed Apache, PHP, and MySQL on the 64-bit Linux server using yum
Then I uploaded my php files for my contact form in /var/HTML/WWW
It displays fine except parts of my contact form are being displayed. They are PHP— the PHP tags and the code within them are being shown.
Here is a live example: 23.23.152.36
And here is a version on another server where its working fine.
Does anyone have any ideas why this is happening?
Do you have PHP enabled on your webserver? For Apache, you may need to modify httpd.conf to enable PHP.
Can you run phpmyinfo() on your webserver?
Enable short_open_tag in you php.ini
short_open_tag
Default Value: On
Development Value: Off
Production Value: Off
shorthand notation is on its way to deprication, i wouldnt suggest building code with shorthand notation anymore.
just use <?php echo ?>
You want to change <?php=$name;?> to <?= $name ?>. That's what you need to do if you want to use the shorthand notation.
I am using wamp server 2.0 on windows XP with PHP version 5.2.5 when I am using the following code
<?
echo "hai";
?>
I am not getting the output. But when I am using
<?php
echo "hai";
?>
Got the result.If I am using the first one in Linux server I got the output.One of my large project like the first one in all php pages.I want to configure with wamp.SO if first coding needs to work what can I do?
My first guess is your php.ini isn't configured for this. The parameter short_open_tag is responsible for it.
Edit your php.ini, search the following parameter and activate it (or add it when its missing there):
short_open_tag = On
More details are in the php-manual.
i'm not using wamp now, maybe you can test solution from http://www.wampserver.com/phorum/read.php?2,50473,50474#msg-50474.
Wish this can help you. :)
I am writing a php app on the websever I set up at my house. It is a fedora10 machine, running php5 and mysql. I have code like this:
<?php echo $var->function(); ?>
But for some reason the -> is closing the php tag, so the output has 'function(); ?' added to it...is there something I need to change in my php or webserver configuration?
I dont think that you have mod_php enabled in your apache config file, or else you would never see the php code in the output. Here is a good tutorial on setting up php 5 in apache.
Try
<?php echo("foo"); ?>
If that doesn't work, you don't have PHP enabled in Apache.
If your're sure that php is enabled, try this one
<?php
$result = $var -> function();
echo $result;
?>
to debug it a little.. maybe something interesting will raise
Is the php enabled on server? A simple test for determining it:
<?php phpinfo();?>
Put the above line in a .php file and access it.
You could also try this:
<?php phpinfo();
Final closing php tag isn't required.
I ran into a similar problem the other day but I was using
bar ?>
instead of
bar; ?>
It turned out that the short_open_tag option was disabled in my PHP configuration.
I had the same problem with a standard XAMPP installation.
short_open_tag=On
Solved it.