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.
Related
I have a php script on a apache dedicated server.
I've cleaned the code to test if header() works... here is the code I test :
<?php
header("Location : http://www.lemonde.fr/");
?>
The page loads and display a white screen, no redirection.
I think it should be a php.ini settingor a apache setting, but which one ?
The first thing to try is changing Location : to Location: (it may be sensitive to the extra space).
Is this the only code? A WSOD is usually the sign of a PHP syntax error, but this looks clean.
I have a simple PHP script that is supposed to redirect to another document after running some code, like so:
if...{
$_SESSION['username'] = $_POST['username'];
$_SESSION['login_status'] = true;
header('location: index.php');
}
else{...
The script works fine on one of the servers I have tried it on but not on the other. As it seems the other server doesn't go to the 'header' row but just stops running half way. All I am left with is a blank page with the title of the previous page. Why is that? Any ideas?
The PHP version on the server that runs the script is 5.1.6, the server that doesn't 4.3.9, not that I believe that has anything to do with it.
Did you started the session? Or your server might be just misconfigured.
Read the logs.
Check from php settings whether session.auto_start is enabled.
Also, it might be that older version of PHP doesn't know how to parse the location: ... string.
So change it to uppercase (so it conforms to HTTP specification):
header('Location: index.php')
Run your code with error reporting, so that you will get some clue about the error
error_reporting(E_ALL);
See PHP Error reporting
I can't figure out why this won't work.
$docRoot = getenv("DOCUMENT_ROOT");
include_once($docRoot."/conn/connection.php");
include_once($docRoot."/auth/user.php");
It works locally through wamp, but it won't work on my live server. I tried this:
if(!include_once($docRoot."/auth/user.php")){
session_start();
$debug = array();
$debug["docRoot"] = $docRoot;
$debug["inc_path"] = $docRoot."/auth/user.php";
$debug["file_exists"] = file_exists($debug["inc_path"]);
$_SESSION['DEBUG'] = $debug;
// exit
header("Location:debug.php");
exit();
}
The debug page just echoes that array and it shows the correct absolute paths and indicates that the file does in fact exist. So why didn't the include_once() work? The server (a DV account on a MediaTemple server) has not been configured at all, so I wonder if there is an apache or php setting that is messing with me.
Ultimately, what I want here is a way to refer to a file in such a way that if I move the file, or include it in another file, nothing will break. Any ideas?
In your debugging you might try is_readable($docRoot."/conn/connection.php"). The file_exists function will return true even if the file does not have readable permissions.
If you get an error code we might be able to provide more info as to what is going wrong.
Turn on error reporting dummy. It turns out one of the includes on another file was breaking this page and I wasn't able to trace that out until I turned on error reporting.
Incidentally, the problematic include was missing a leading slash in the filepath ( include("dir/file.ext"); ) which works on my local wamp setup and breaks on the linux server.
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.
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.