I have a test.php script which contains this:
<?php echo 'test'; ?>
When I point to it via my browser, it works and prints out "test" as expected.
I have another script which I am trying to test but however, it is ignoring all my echos! I thought I would put an echo right at the top as this will surely work, but when I get to this script via POST request from a form. It does not even echo out what is at the top of the line:
<?php echo 'START START START';
error_reporting(E_ALL);
I even point to from my browser and still no output?
What the hell is going on?
Update
The error log shows this :
PHP Parse error: syntax error, unexpected T_ECHO in /var/www/tester/convertor.php
But the echo is at the top of the line. I am going to set diaplay errors.
You have a parse error, so the script isn't even executed. So it's expected that it won't output anything.
The parse error can be for any echo in the script. It may be because of an "echo" statement after a line missing a semicolon, for example.
Things to try:
Check your error log
Check the headers (is it coming back 404?)
Make sure you view-source: don't just look in the browser
Delete everything except the echo. If it works, add things back a bit at a time until it breaks.
Load your script in a hex editor and make sure there aren't any weird characters in there
Are you including this file from another file? If so, check the other file too. Watch out for output buffering.
Put exit; after the echo start start start and see if that works. Look in the apache error log for clues. Comment out the rest of the PHP code in the file and see if it works then...
UPDATE
I have had this when copy pasting white space from a browser sometimes - e.g. copy/pasting some code from a web page. Sometimes weird control characters get embedded invisibly in the white space, and I find that deleting the whitespace and re-entering it fixes it. Did you copy paste anything into this file?
Are you hosting this page on a server with PHP installed?
If you just have a .php file on your hard drive somewhere and open it in a web browser, it won't work. You need to be running a web server with PHP extensions and access the file using the HTTP or HTTPS protocols.
On a similar note to this i have seen alot of scripts throw errors like this when they have come from developers on windows (i'm on linux).
I have to go to the start of the php file and hit delete a couple of times to get rid of some invisible characters before the script will run.
You're missing the ending ?>
<?php
echo 'START START START';
error_reporting(E_ALL);
?>
Related
i want to know if exist function to know if my file have errors before include it just on the script as code bellow
if (file.php==errors ){echo"this file contain errors"} else { include("file.php");}
i want to use this php script to know if my file.php contain errors , if it contain't errors i will not include it , else i include it .
No, it's not possible. If you include a script in another script, and then execute that script, then PHP evaluates the whole combined script as if it was one file. So if there is a syntax error in any of the included scripts it will cause the whole thing to fail. That, naturally, happens before any of your other code can run. Your whole concept simply doesn't make sense. If you have syntax errors, test the scripts and fix the syntax errors before the code goes live.
And, as the comments suggest, if the real issue is that some files do not get deployed properly, then the solution is to fix the issues which are causing the deployment to fail.
I am developing w web site. Here I have included a thumnail page. It’s working well in my localhost. But when I uploaded its show me an error see
Warning: Cannot modify header information - headers already sent by (output started at /mydomain/demo1/admin/thumbnail.php:50) in /mydomain/demo1/admin/act-addVehicle.php on line 191
my code
if(move_uploaded_file ($tmpName,$path.$actual_image_name)){
$succ=1;
chmod("$add",0777);
$imgSucc=1;
//strt image thumbnail
include("./thumbnail.php");
// ends
}else{ echo "Failed to upload file Contact Site admin to fix the problem";
exit;}
How I avoid this error
is there any settings in php ini ?
does anyone know ?
please reply
Without seeing thumbnail.php's code its hard to tell exactly what's happening, but basically its outputting something before act-addVehicle.php on line 191 is setting another header.
Most likely a single space at the end of the script. Check after ?> perhaps line 50 if just after.
You could wrap the include('thumbnail.php') into an ob_start() and ob_end_clean() but that will not solve the underlying issue of outputting before setting a new header.
This kind of error typically comes from having a closing php tag in one of your file that is followed by some white space. This white space is sent to the browser when the script is executed BEFORE it executes a "header()" function.
For example, I would not be surprised that your thumbnail.php or act-addverhicule.php ends with a "?>" tag and that there is some white space after it.
As a good practice, it is always better to remove all closing php tag (the "?>") at the end of your files to avoid these kind of problems...
of course. use ob_start funciton somewhere in the beginning of your code
Alright this is what my code looks like
index.php
require_once($WebsiteRoot . "/include/testfile.php");
TestFunction();
/include/testfile.php
function TestFunction()
{
echo "It Works";
}
And it gives me the error:
Fatal error:
Call to undefined function TestFunction() in /path/index.php on line 49
Any idea what i'm doing wrong?
Thanks
You haven't included a <?php tag in the included file, so it's just interpreted as plaintext input.
Remember... there's no such thing as a PHP script. There's only files which contain PHP code blocks. Without at least one <?php opening tag, the PHP interpreter will never be invoked and the file's contents will simply be treated as output.
try calling another function from testfile.php, if this is'nt working, its something with the include. Add the code:
error_reporting(E_ALL | E_WARNING | E_NOTICE);
ini_set('display_errors', TRUE);
to the top of index.php and refresh the browser to see your errors, try debugging from there.
The problem that i can forsee is that you are using a URL instead of a path, your $websiteRoot variable should contain a path like:
$websiteRoot = "/var/www/html/websiteName";
OR
$websiteRoot = "C://xampp/htdocs/websiteName";
instead of a URL like:
$websiteRoot = "http://www.somesite.com";
I had a similar issue. I dug into the PHP in the included file and found an invalid PHP tag. I had <? instead of <?php. PHP 7.2 and earlier forgave that, but PHP 7.3 was throwing that same error you faced.
Make sure you're including the file you think you are. If your index.php page looks exactly like you've stated, then it won't return anything.
If you want to link to the same location from anywhere on the site without worrying about relative locations, then at the beginning of the file, put:
$WebsiteRoot=$_SERVER['DOCUMENT_ROOT'];
And it should work fine, provided your file would be located at http://mywebsite.com/include/testfile.php
Try renaming the included file.
I had an included file with the name "system.php". It looked as if the include command was just skipped. Even with the most strict error reporting there was no message and even an echo command in the main body of the included file did not produce output. It had worked ok under PHP 5 but after the upgrade to a 7.2 environment these problems arose. After much effort - I forgot how - I managed to get an error message. It said there was a conflict with a PEAR class with the name "system". Yet my file didn't contain any class, just variables and functions. Anyway, giving the file another name than "system.php" worked for me.
I hope someone else can add a more technical comment on what was going wrong here.
I've to make a website works and I don't know what to do right now. I can run it in a virtual machine with Ubuntu, on my company's server in Debian, on a WAMP... but I can't get it working in a server from a client.
I think the problem is with the gets. The form that I can't modify is sended by get, using the next url:
http://domain.com/SGAP/dades_proj_edit.php?idedit=2011854&id=&projectname=afsdfasdf&comptitle=asasfdafsdafs&codarea=ECIV&grauimp=1&codtipus=2&codsubtipus=6&subtipusdef=fdsaafasfddfs&codpais=8&clientid=2&promotor=asdfa&entfin=fsdafadsfds&impcontract=2&initdate=21%2F01%2F2011&findate=30%2F01%2F2011&uteflag=false&utepartic=&utepercent=0&descprelim=fdsadasdadfsadfs&codprojstatus=1&statusstamp=25%2F01%2F2011&cruserid=&action=update
Firefox shows a blanc page with no error. I've tried to force to show all errors with error_reporting(E_ALL) and ini_set("error_reporting", E_ALL) to show if something happens but the wait page is showed with 0 errors.
I supposed that was a $_GET error and I tried to put on the top of the page and in the end of it a <?php if($_GET["test"]) echo "Works"; ?> and call the webpage with: domain.com/SGAP/dades_proj.edit.php?test=testing and it works from top to end... I don't know where is the error.
What I can check to figure where is the white page comming? Thank you in advance!
Here's what I would do.
Start at the top of the file/stack, and add this code:
<?
$myUniqueCounter = 0;
error_log(++$myUniqueCounter . ', line ' . __LINE__ );
Then, copy and paste the error_log line all over the file/stack, and see where it stops logging.
I have occasionally seen php die without a blank output. Generally, the only way to solve this is to remove everything from the file, and then add code back in one line at a time. When it stops working, you know that whatever you just added caused the fault. You can try running php with the -l flag, to check the syntax, but this might not find the problem; the only sure way really is to just to add or remove things until the output changes.
I know this isn't much help, but there is no other way to debug the problem, short of executing php itself with a debugger... actually, you could do that; can you run php from gdb? That might help you find what is causing the issue, but no guarantees.
I have a strange behavior with PHP system function. In this php script there are only 2 instructions (the rest being pure html):
<?php echo system('cgi-bin/gallery2/galleryheaderview.cgi'); ?>
<?php echo system('cgi-bin/gallery2/galleryview.cgi'); ?>
The first cgi just returns a single line as you can check here
http://reboltutorial.com/cgi-bin/gallery2/galleryheaderview.cgi
It returns
My Gallery
But the whole php script returns My Gallery Twice:
My Gallery
My Gallery
http://reboltutorial.com/gallery2.php
Is there a reason (I don't use My Gallery in second cgi script of course see http://reboltutorial.com/cgi-bin/gallery2/galleryview.cgi) and how to prevent this ?
Thanks.
Update: The system function will do two things. The first is, it will run a command and pass its output through to the browser and/or output buffer. The second is, it will return the last line of output. So when you're saying
echo system('/...');
You're saying "Hey system, output the results of this command" and then "Hey ehco, output whatever system returns". Removing the echo
system('/...');
will fix your problem.
A few other things to check
Are you sure its galleryheaderview.cgi that's returning things twice? Comment out the include to make sure its actually the script that's echoing My Gallery twice
Is your PHP page/program included/constructed in such a way that galleryheaderview.cgi is being called twice?
Are you sure that calling the URL http://reboltutorial.com/cgi-bin/gallery2/galleryheaderview.cgi is calling the same command line as cgi-bin/gallery2/galleryheaderview.cgi?
If you've checked out the three items above, you'll need to drop into the source of galleryheaderview.cgi and see why its outputting the header twice.
Are you absolutely sure that nothing else is outputting the My Gallery before this line? You should try removing it, and see if it goes completely away or if there is still is one "My Gallery"
<?php echo system('cgi-bin/gallery2/galleryheaderview.cgi'); ?>
If this doesn't bring you any further, maybe you have included some php file twice?