PHP header() gets sent after ouput - php

Until recently, my LAMP was working as I expected and using PHP's header() to redirect behaved according to documentation. Out of nowhere, this changed. The problem can be seen here:
<html>
<head>
<title> BLAH </title>
</head>
<body>
<p> TEXT </p>
<?php
echo "BLAH BLAH BLAH";
sleep(10);
header("Location: http://example.com");
?>
</body>
</html>
As far as I know, the redirect should not occur - but it does. I tried echoing, adding HTML, waiting to avoid any possible race conditions, all to no avail. When I access this page, no output is shown, and after 10 seconds I get redirected.
I wasn't very lucky searching the web as most people have exactly the opposite problem, nor did I find anything useful in the server logs. I haven't done any configuration changes or package updates. The people I asked were also puzzled.
I'm running PHP 5 and Apache 2 on a CentOS virtual machine.
P.S.: My first question here, but reading this site has helped me many times and I just love it :) .

Thanks Raoul, that was it.
I totally forgot I had been working on another Debian machine before the VM. And, of course, its default php.ini was different from that of the CentOS's.
Debian had output_buffering = Off while CentOS was set to 4096.
Also, PHP errors were disabled on the VM.
Thanks again, guys, it's very reassuring to know it's not an obscure language quirk or an elusive design flaw. Cheers.

Related

PhpStorm local web server truncated output

So, here is a problem: when I launch index.php on local server a portion of code after sertain point is missing (usually around last 30% of html code, but it seems pretty random). If the php file is small, it works fine, but it struggles with 200+ lines.
When I launch http://localhost:63342/test/index.php the html ends like this:
...
<header class="mdl-layout__header">
<div class="mdl-layout__header-row">
<span class="mdl-layout-title">Главная</span>
<div class="md
When I launch file:///C:/test/index.php or on the external server it's fine.
HTML is correct, checked via validator.
It's a PhpStorm issue. Please vote: https://youtrack.jetbrains.com/issue/WEB-17803
This bug is fixed now, according to the devs:
28 Sep 2015: Build with fix should be available during this week

Firefox: connection determined in PHP script

I've set up an Apache Server as localhost in a openSUSE 13.1 64 bit system and I'm currently testing my PHP scripts.
In Konquerer 4.11.5 everything seems fine, but with Firefox 29.0.1 there is a strange phenomenon:
Every 10th time or so the connection fails. Firefox reports: "Connection determined".
The failed connection is listed neither in error_log nor in access_log.
The error must be quite "early". Because my PHP script output.php calls "itself" via
header("Location: output.php?changed_url");
almost immediately, but the Firefox error is BEFORE output.php is opened for the second time.
I have no idea what to do about this. It's a quite annoying issue.
All answers will be appreciated! Thanks in advance!
I guess you are missing
exit;
after the header() location change.
So you have an open script, firefox redirecting to the next (itself) and still having one open, ... I think firefox doesn't like this kind of loop ;)
Do you have any .htaccess file there? Have you tried using firefox from different OS or computer? I bet it's related to your installation of firefox :) (i ain't pro take it as guess)

PHP Reload Time

Hello I have a Problem with my PHP. Im coding in two ways:
I upload a File to my FTP Sever
Save it Local and run it with MAMP (OSX)
But in both ways i save/upload the new file but it takes about 2-5 Min until i can see the changes.
Example:
Old PHP:
<?php
echo "test";
?>
New PHP:
<?php
echo "test2";
?>
So i save the second file but until i see the second text it may taxes aboout 2-5 Minutes?
Can i change something in my PHP Info file or something else ? Or is there another way to code in PHP ?
This sounds like a caching problem. Try hitting Cmd+Shift+R* and see if the changes are instant then. If that's the problem, see this answer for how to disable the cache to prevent this problem.
Also, as loveNoHate points out in the comments, it is possible that this is a server- or ISP-side caching problem. Because you have the same problem running it locally on MAMP, however, it sounds like a browser issue.
* The Mac OS X shortcut. For future visitors: you would use Ctrl+F5 for Windows.
Since this is mac you might want to do
For Safari: Opt+Cmd+E to clear cache and Cmd+R to refresh
For Chrome: hold down Cmd and Shift key and then press R.

XAMPP PHP is not working

I have just installed XAMPP again, I was using IIS but I have now disabled that.
For some reason disabling it didn't seem to work, as the ports still clashed, so instead I have changed the port for Apache to "1234".
As you can see from the control panel below XAMPP seems to be running just fine, the index page shows up fine at least.
I made a quick test page and placed it in my install directory (C:\xampp\htdocs\testing.php)
<?
$test = "hello world";
echo $test;
?>
I then load this location in Chrome: http://localhost:1234/testing.php
But for some reason the page is blank, when I view the pages source I see this:
<?
$test = "hello world";
echo $test;
?>
Any ideas?
Edit:
Fixed thanks, I was an idiot and didn't open it with
Instead of wasting this thread for such a stupid mistake here is another question.
Is there a version of Chrome or Firefox I can use to run my website but lock it in full screen and require a password to get out of it?
Try to use <?php tag instead of <?, this is often disabled in standard php installations.
BTW, to activate short tags, the property is
short_open_tag=On
in your php.ini.

IIS 7.5 Express + PHP echo shorthand

i'm a PHP developer, and trying Webmatrix lately,
I have successfully install PHP to IIS, and use it, it's pretty neat I say
then, one time i hit this problem
while
<?php echo "Hello World"; ?>
or
<? echo "Hello World"; ?>
works just fine,
but
<?= "Hello World"; ?>
is not working at all, and i thought it was my mistake, then i start apache, and run it from there, and it works..
So, how to get to work?
It work on apache, but not on IIS.. anyone having same problem?
I'm using PHP 5.3.8 + IIS 7.5 Express + Web Matrix
Thanks
Resolved
OK, I have resolve this problem,
The answer is simple and annoying, I'm using Windows 7, the main problem is UAC,
every time i save the php.ini, it's saved to the Virtual Store instead of the original location (because i dont use administrator right when editing)
I tried to edit the php.ini under administrator right, and Boom! worked like a charm!
Thanks for your answer
Check if the short-open-tag is enabled in your php.ini
http://www.php.net/manual/en/ini.core.php#ini.short-open-tag

Categories