I had document addsite.php like below.
<?php
session_start();
if(condition){
///Include this document
include_once('sub_docs/addsite.php');
}
else {
die(header("author"));
exit();
}
?>
And my addsite.php in sub_docs is an combo of both HTML and PHP as below
<!DOCTYPE>
<html>
....
....
<?php
?>
....
....
</html>
Everything is working fine in my local server but when went for production it is just showing the blank page. Not even a single markup tag. It is even entering the conditions and just stopping there. Neither of the die or include_once are working. There is no problem with any sql statements or the php script in between the html. I can't find the mistake. Please help.
Try turning on some error reporting so you can see what's happening:
error_reporting(-1);
ini_set('display_errors', 'On');
Also - make sure your secondary page is a .php file and not an .html, unless of course you have it setup in your .htaccess file to allow .html to run as php.
Related
When I put some PHP code in index.php, my PHP code does not show up in my browser (I use firefox). In Firefox's dev tool the PHP code
<?php include 'header.php'; ?>
becomes
<!--?php include 'header.php'; ?-->
It is on Codeanywhere, HTML container on Ubuntu
Just try to see the tutorial first. http://docs.codeanywhere.com/quicktutorial.html
I have a strange problem .... I made an php (some_name.php) file combined with some html and uploaded that file to my webserver.
The file has the code inside structured like this:
<html>
<head>
some html code
</head>
<body>
some more html code
<?php
some php code
?>
some more html code
<?php
some more php code
?>
again some more html code
................
</body>
</html>
When I try to view the file/page in my browser ..the page is not displayed after the first block of php code (no errors ..page works well on my localserver) ..so basically I see just the firs part of the page ..not any html code or php code after the first block of php code ends ( first "?>").
Anyone can help me with this? How can I see the full page, why it not execute the rest of the code?
I put this piece of code
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<html>
<head>
some html code
</head>
<body>
..........................
at the beginning of the file and still no errors are showing ... and still I see just a part of the page.
It is most likely some reference that is different between the localhost and webserver, and you will probably need the error to pinpoint it. If you don't have access to/ can't find the php error log, You can temporarily display errors by adding
ini_set ('display errors', 1);
error_reporting (E_ALL);
To the top of the page. If you throw up some code it might be obvious enough to pick out the issue.
**sorry about the formatting, I can't seem to get the mobile editor to cooperate.
I'm trying to use PHP to print out values for my select statements but I can't get it to work. I've even tried just to print something out in my html with php, but i can't even seem to do that. Can anyone tell me what's wrong with this
<html>
<head></head>
<body>
<ul>
<?php echo "register Student:"; ?>
</ul>
</body>
</html>
Make sure you save your file as .php not .html.
myfile.php:
<html>
<head></head>
<body>
<ul>
<?php echo "register Student:"; ?>
</ul>
</body>
</html>
You will also need to run this file on a server that has php installed. It won't run directly in the browser like an .html file will.
Keep these things in mind.
Your file name should always end with .php extension not .htm or .html
You should always run file on localhost/ where you set up your environment
Please follow the standard of W3C Use a "li" in you "ul"
Hope it works.
Name your file whatever.php
Make sure it is NOT whatever.html
If that doesn't work, be sure to check whether or not you installed php. I suggest a local testing ground such as XAMPP. If you don't want to do that, upload it to a free or paid hosting service.
I have an html file which has inline php. The index.html looks roughly as follows
<?php session_start(); echo $_SESSION['xxx']; ?>
<form action=blah.php> ... </form>
And in blah.php, I do a
$_SESSION['xxx'] = "foo";
header('Location: index.html');
However, when index.html is shown for the second time, I do not see the "foo" message.
Then check your server settings. Try to set send session values in address line (like GET request).
Run this bit of code before your starting your session. It's possible there is an error accessing the session file
ini_set("display_errors", "stdout"); error_reporting(E_ALL);
PHP cannot parsed by HTML files, I mean PHP codes cannot run by HTML, you can try like
<!--#include FILE="test.inc" -->
Above code is HTML file include and put your PHP codes in .inc file, but you have to make some changes in Apache
I have 2 files:
create.php:
<html>
<body>
<?php
require("Test.php");
hello();
echo "does this work?";
?>
</body>
</html>
and Test.php:
<?php
function hello(){
echo "hello";
}
?>
But when I open create.php, nothing prints (not even "does this work?". If I call hello() from Test.php it works fine. That is, it doesn't seem to be executing code after the include. What am I doing wrong?
edit: the code seems to work fine in my IE 8 install, but not in my FF 5 install (which, admittedly, has way to many addons).
edit again: the issue was that the page cache needed to be refreshed. There was never a problem. The code works. sorry, all.
Do yourself a favour and turn on error reporting. Place the following code at the beginning of create.php and let us know the error message(s) you receive.
<?php
ini_set('display_errors', 'on');
error_reporting(E_ALL);
require_once('Test.php');
?>
My guess is that it is a path issue.
First of all, you do not need the html tags in your PHP-File. Second: you need to execute your function. Now you only defined it. Try
Test.php
<?php
function hello(){
echo "hello";
}
hello();
?>
And make sure that both files are in the same directory.
use dirname(FILE) instead of a stright include
eg
if i have a dir
/var/www/html/include
and test.php resides in includes and your script is in html then use dirname(__FILE__).'/includes/test.php
if you need to go back in a dir the use dirname(dirname(__FILE__))
depending on how many levels.
it also makes it dynamic so command line and browser will always fin the file
Try the code below for create.php
<?php
require('Test.php');
?>
<html><body>
<?php
hello();
echo 'does this work?';
?>
</body>
</html>