could you help me to troubleshoot why I suddenly can’t render PHP files in my browser or the preview pane of my text editor (Panic Coda) please?
I use a combination of PHP scripts and the Smarty templating engine to write html files for email newsletters. Up until midday today, when I use the Coda preview to run the PHP scripts, the layout renders fine and the html file writing included in the script also worked.
But then suddenly, when I preview the file, all I see is the PHP script in the preview pane – see screen shot.
This happens occasionally, but it is usually enough to quit the application and start it up again, or restart the computer. But not this time.
Apache is on? Check.
Updated to macOS Sierra? Not yet.
No other substantial systems changes? Not that I can think of. Certainly none in the last few hours.
It was this:
Make sure you are accessing your file over your webserver using an URL like http://localhost/file.php not via local file access file://localhost/www/file.php
found here: PHP code is not being executed, instead code shows on the page
Related
Whenever I have to test a design change on an HTML page that's written within an PHP file, I have to make the effort of first uploading it to the webpage and then viewing it through the browser. Normally, if it was an HTML file, you'd just update the browser and see the changes locally. Of course, it's not possible to execute PHP on a browser unless you use XAMPP or whatever, but I consider that to be too much for simple debug. Isn't there a way to open a PHP file as just HTML, ignoring all PHP code for debugging purposes? If not, then I'll just get it with XAMPP. Thanks in advance.
PHP has a built-in webserver, you can utilize that i guess.
php -S localhost:8080
If the script does not require the http stack (which i doubt), you could also do:
php index.php > index.html
Update:
After you executed the command above (php -S), simply type the same url in your browsers address bar.
I have a quite simple php page (PHP 5.5.35 on CentOS 5.11) that queries a MySQL database. The resulting page shows completely, including the footer I include as a final instruction, so the PHP script runs entirely without error.
Almost every images and js libraries are loaded. However, there are two elements that are never loaded, an image and a jquery library. Each time and with any browser, those elements generate a (in Chrome, for instance) :
Failed to load ressource : net::ERR_CONNECTION_RESET
For testing purpose, I tried to delete those element from the page, ultimately, it is the favicon that can't be loaded. So it seems not to be those elements in particular. The connection seems to be reseted at some point between the PHP script completion and the page loading… and I don't have the beginning of any clue where I should start the troubleshoot.
Some other informations :
Apache logs don't log anything !
The other pages of the site works well
The site works without any problem on my local machine (Mac OS X, PHP 5.5.35 too)
Once the page is loaded, if I click any link on it, it shows a "Connection reseted" error page.
Does anybody have a clue, anything about where to start my search ? Thanks in advance, I am starting to desperate.
It happened that after searching everywhere, the cause was simply that I was handling a lot of parameters through GET – too many of them. I changed the code for using POST and everything worked miraculously… Hope it may help someone, sometime !
Php is a server side scripting language.. So, if i make my PC work as a server in a network, will I be able to see the php code executed on my machine? As html is seen on all client PC's?
Not only will you be able to see the php code on your server, you will even have to put it there first. Your server will not run other servers' PHP code if that is what you had in mind.
If the webserver is configured correctly then you can only see the code directly on the server as with every other local file on a server/pc.
Other machines that access your internet pages (in case that the php files are for a webpage, as I have seen some usages of php files for maintenance utilities instead of web pages in the past) only see the results of the php code not the php code itself (thus only what you echo or specifically print out to html in another way). This is because the webserver processes the php file and the clients only receive the results of the php files not the source files themselves.
Aside from those two cases I've seen it in the past that if a webserver is NOT correctly configured, it can be that the clients see the php code itself instead of the results (as the webserver does not process the php parts). In these cases yes the clients can see the php source (not sure if this is also true for the current versions of webservers though. At least in the past it was that way).
As mentioned there exists also the option to use php files as programs that run locally (for example started via a service that calls php myphpfile.php). In these cases it is as in the first case that the sourcefile itself can normally be accessed as every other local file on the server itself, but as it is not in a webserver directory clients (aside from network shares,...) won't be able to see anything of the file itself.
Yes, you can see your code by using ssh like putty you have to login to your server using a user account of server. Follow the following tutorial. You will be able to log into your server remotely and you can see and even update the files on server.
http://kb.mediatemple.net/questions/1595/Using+SSH+in+PuTTY+%28Windows%29#gs
You can open the folder containing the source PHP files and open them with an appropriate Editor (Notepad++, Sublime Text...)
I'm just getting started with PHP and writing echo statements to help me debug. I saw on here recommendations for Chrome Logger. I've installed the Chrome extension and I can see it in the upper right corner of the browser. I also downloaded ChromePhp.php and uploaded it to my server in the same directory as my php file I'm trying to debug.
So then in my php at the top of the page I've written include 'ChromePhp.php';
Then when I render that page from inside Chrome I expected to see the menu bar as shown on the Chrome Logger website showing Elements, Resources, Network, ..., Console, etc.
But instead i'm seeing a page that looks like this attachment and then my code way at the bottom. It's as though my include statement isn't working and it's instead just displaying the entire ChromePhp.php file in the browser.
What am I doing wrong?
I think you did 3 mistakes:
1) Chrome Logger extension works in combo with ChromePhp.php for the situation where you run PHP code hosted on a server where you only have FTP access (and cannot change PHP paramenters, nor can debug PHP code on the server).
You didn't mention if that's your case. If you're running a local PHP server on your computer, you don't need the Chrome extension for debugging.
2) Your screenshot shows this GitHub page, not your own PHP page: https://github.com/ccampbell/chromephp/blob/master/ChromePhp.php
That means you should try the Chrome extension on your own PHP website, not on the GitHub website.
3) Once you're on your PHP website, right-click in Chrome and choose Inspect. That will make you see Elements, Resources, Network, ..., Console, etc.
I have written a .php script. When there is some event, it writes to a file. It's working perfectly!
Now I want to open Windows Media Player or any other player using this php script as I also want to play a sound when the event occurs. I tried embedding the sound file as follow:
echo "< embed src =\"$file\" hidden=\"true\" autostart=\"true\">";
But it only writes to the file n do not play the audio, when the event occurs.
I came across 'exec' command which didnt work. (I am not sure about how it works. An example would be a great help!)
Does anyone know how to start a windows application using php script?
EDIT REMOVED
Thanks,
Sagar.
You can play a wave file in your server side folder in a php file by adding this
<?php exec('c:\windows\system32\cmd.exe /c START C:\website\beep.wav');
?>
and this would play the beep.wav usually through whatever sound appy is installed on your machine, like windows media player.
You cannot start console based application through Apache+PHP application. The reason is, as Apache webserver is running as a system service in a separate logon session, it cannot start UI based applications which requires a login console session.
Anyway, you can embed the audio inside the html page. Refer the http://www.w3schools.com/html/html_sounds.asp page to get more details.
Comment about running Windows GUI programs using PHP: http://www.php.net/manual/en/book.exec.php#87943
But, I think you only need to embed player on your page using some HTML tag as Aravind described.
SagarJ,
You can embed the audio file in html and will be executed by the browser/browser plugin application already installed in the system.
So, you need not to worry about that.