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!
Related
I recently setup a MAMP environment (v3.5)` to test my website locally rather than having to upload to the host.
The PHP works fine on the remote host, in this case the form will submit.
Here's a link: PHP Form
When I run the site locally only html and css work but the PHP pages show the first few lines of the POST sequence.
Partial run
This is the content shown in the viewport
Content-Type: application/x-www-form-urlencoded Content-Length: 59 sendername=&senderemail=&contactno=&user_message=&send=Send
As you can probably guess, this is not the result I am expecting. In the normal scenario, the acknowledgment.php page will load with a 'thank you' message.
Can anyone tell me what is wrong with the MAMP installation that would cause this?
Thank you very much indeed.
check if you put the method="post" attribute in your form
check if you close each tag
Check the version of php on your mamp: preferences -> php
Reeinstall your mamp
in any case if it does not work, you can try manually install php
other think will be that you post your code of file acknowledge.php to check for possible errors
I hope it helps you...
Thank you guys so much for your insight. I am so humbled by the help provided here!
I opened the acknowledgement.php file only to discover that somehow the content had been erased leaving only a few lines.
I corrected it, using the file from the remote host and it is working now!
I know this has been asked tons of times here and all over the internet however solutions I found are not working and this has been driving me crazy for several months now.
I have a very simple PHP page:
<?php session_start(); ?>
I'm getting the nightmare errors headers already sent and cache limiter in my error_log. Although it doesn't affect the function of any of the scripts but it's filling the error_log so much. There is no error when running from browser.
I have tried the TextWrangler editor for Mac and choosing Unicode UTF-16 with no BOM option when saving. However, after creating the file using Textwrangler, making sure that the extension is PHP, and uploading the file to server. I tried running the file directly and I got the following in browser:
<�?php session_start(); ?>
So the file is not encoded properly. I don't know why. With regular encoding of UTF-8 from either TextEdit or TextWrangler, the header error would appear in cron job as stated before.
I write all the text myself without copying so that no BOM characters in the file. Is there any REAL solution for this error? Should I use an ANSI editor? Isn't the save as utf-16 with no bom option used to avoid this errors? Or this errors must appear if there is session in cron?
Lastly I use the following cron job in cpanel: php -q /path/to/file.php
Calling your php script from cron will invoke PHP-CLI environment, which is not the same as calling the same script from the browser.
For example there are no cookies and obviously there is no session by default.
However if you still want to enjoy the sessions , there is a way. You can try this:
<?php
session_id ("temp");
session_start();
print_r ($_SESSION);
?>
If you give us information about the final goal or the use case behind this script we can help you more!
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)
Ok, this is a strange one. I've recently moved over to Mac OS running Lion and set up the PHP version that comes with OSX. Everything's running as I expect except for one thing and I can't understand why!?
As part of our CMS, menu data is cached into a php file as:
$menuData = unserialize( $menuString );
where $menuString is a long string of serialized data. I've used the same thing successfully on a PC running WAMP and on numerous linux boxes without problems, but since I've moved to the Mac OS, every time I include the file, it prints a long string of question marks (even if the above line is commented out in the file!!). Initially, the $menuString was around 280k, but I've also tried this with a menu string of less than 6k without success.
Is there a PHP setting somewhere that might exhibit this type of behaviour? I'm baffled and have tried numerous things!??
Please help!
UPDATE: I've gone though the PHP.ini line by line on my Mac and the one I was using in WAMP and see no differences so don't expect it's anything directly set in there. Everything else in the setup is working exactly as I expect and all other site features and functions are working!? Is there something obvious in terms of native set up that I'm missing?
If it happens with that line commented out then it probably isn't that line... Try dos2unix to fix up you line endings... Aside from that grab hex edit and poke around the area for strange nonprinting chars...
Well, long and short of it is I used a workaround in the end. At the point of creating the big long serialized menuString, I saved that to a txt file with no php in it and then did a
$menuData = unserialize( file_get_contents( [Textfile] ) );
Seems to have solved the problem!! I'm still confused as to why it occurs, but at least it's working!
I'm having a critical issue where my WAMP installation for PHP 5.3.0 is not finding a file which exists within my computer. Does anyone know anything about this? Possibly a PHP Bug?
Any help would be much appreciated.
Here is the variable which creates the file:
$baseNewsUrl = "C:/reviews/reviews/$platform/$fullname";
And here is the code which grabs the contents:
if(is_file($baseNewsUrl)){
$contents = file_get_contents($baseNewsUrl);
} else {
echo "File not found. " . "\r\n";
continue;
}
Here is the output of $baseNewsUrl: C:/reviews/reviews/GBA/r20107_GBA.htm
And the file does exist.
Check that the entire path leading up to your file is readable by the user PHP is running as (if you are using IIS, this might be something like "Network Service," although I am not particularly experienced with PHP on Windows). Also, check whether the INI directives "open_basedir" or perhaps "safe_mode" are set--these would give PHP self-imposed limits on which files are accessible.
Do a var_dump (not an echo) on your variable.
var_dump($baseNewsUrl);
and look at the actual contents. You may have some invisible garbage characters in there that's preventing Windows if you're doing this in a browser to make sure there's no empty tags (or other browser-render-invisible) characters.
If that doesn't reveal anything, remove the is_file check and try to open the file with file_get_contents (or any file related function) and var_dump it's contents. You'll either open the file, or PHP will spit out an error/warning/notice (either to your browser or to your error log) that should let you know why it can't open the file.
I'm gonna say this, and it very well might not be your problem but it is a recurring one for me. If you use skype on your computer, it has a somewhat known compatibility issue with WAMP. It cause's WAMP to be unstable, not load files properly.. everything.
on windows
$baseNewsUrl = "C:\\reviews\\reviews\\$platform\\$fullname";
It's due to Windows Vista and WAMP.