I was transfering my website from Hostgator to a new server.
When I open the PHP page in my website, it will download the page rather than execute and showing the page, but if I open the HTML page, image, etc. It will open it like it should be.
What should I do so my Website can run the PHP script and showing the page rather than downloading it?
Add some handlers to your .htaccess file so that it will recognize the php files and execute them as they should be
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.
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
Is it possible to set up a cron job to download the content of an iframe (the iframe loads into my website currently, content is served from another website) and cache it to a php file (or another file like HTML etc) so I can serve the content without it having to reload on every page refresh etc and without actually using the iframe in my website.
If not a cron job just something similar, a server process so the content is already cached on the server daily without it having to load from another site when a visitor loads the page.
I will try to explain on example.
There're files on the web I publish (let's say, something.pdf or thefile.zip). I want, before actual download when user follows the link to file, some php script to be invoked which then will return the requested file. How to do it? Please advise. Thank you!
Edit 1: thanks amadeus. In my case PHP script is located on the other server than web site and files to download = PHP script will need to read file from remote web server and send to client, which is extra traffic... I actually does not need PHP to control file download. It is ok to have it downloaded from the web server, but I want PHP script to be invoked when download is requested (to gather info on who is downloading and how many times).
Edit 2: thank you Pekka. I just realized that it is even more complex. Imagine server1 is webserver with downloadable files on it (no php), and server2 is php server. If I just give "server1/thefile.zip" I will be unable to invoke script from php server. Then it seems I should use "server2/script.php?thefile.zip" which will then just redirect client to the file on server1. Is it the best implementation in given conditions?
It is ok to have it downloaded from the web server, but I want PHP script to be invoked when download is requested (to gather info on who is downloading and how many times).
That's easy to do by calling
header("location: http://externaldomain.com/externalresource.zip
from your PHP script when you are done counting.
This will redirect the browser to the external resource.
I have a script which logs you into zencart when you open it in your browser.
Now when I try to call this from inside another php script using require, header, or curl, it does not login to zencart. It only works when the user opens the php script directly in their browser.
I also tried virtual(), but its running the index.php script for the top level of the site, not the file I specify. Thanks.
I got this working by reading the session from the database. Let me know if anyone is interested and I will open up a github. Thanks!