Possible to View PHP Code of a Website

How can I view PHP source code on a live site?

No, as it is interpreted on the server-side and the results are sent to the user. If you want to view the source code of a site you control in-browser, consider the FirePHP extension for Firebug, or just access your site files with your preferred method.

Possible to view PHP code of a website?

A bug or security vulnerability in the server (either Apache or the PHP engine), or your own PHP code, might allow an attacker to obtain access to your code.

For instance if you have a PHP script to allow people to download files, and an attacker can trick this script into download some of your PHP files, then your code can be leaked.

Since it's impossible to eliminate all bugs from the software you're using, if someone really wants to steal your code, and they have enough resources, there's a reasonable chance they'll be able to.

However, as long as you keep your server up-to-date, someone with casual interest is not able to see the PHP source unless there are some obvious security vulnerabilities in your code.

Read the Security section of the PHP manual as a starting point to keeping your code safe.

Is it possible to read php code from other sites?

It is only possible if the site's owner intentionally makes the code publicly available, or if the site has a very critical security hole. Usually, no, you cannot read other people's server-side code.

After all, we'd have huge problems if you could just read any server-side code you wanted. If, say, a bank's website were built in PHP, it would be important that raw PHP files could not be read by the public: they might contain private data like database passwords, or simply make it much, much easier to find other key security issues, since, after all, which is easier—finding problems with code you can see, or code you can't see? As much as I am a fan of open-source coding, I would not put my money in any bank that makes its source code available. It's just too risky.

However, if you're interested in learning, there are plenty of open-source web applications out there. Try searching Github for, say, projects written in PHP. It's definitely a good idea to read other people's code, and I'm sure you could find some stellar examples of real-world code if you know where to look. Additionally, if you ask nicely, a website owner may be willing to share parts of the source code with you, though probably not all of it, for security reasons. Couldn't hurt to ask.

Can anyone get access to my PHP source code?

With a correctly configured web server, the PHP code isn't visible to your website visitors. For the PHP code to be accessible by people who visit your website, the server would have to be configured to display it as text instead of processing it as PHP code.

So, in other words, if you visit your website and you see a HTML page and not PHP code, your server is working correctly and no one can get to the PHP code.

How do I show / run a PHP file in a browser? As if it was a webpage

You need to download a server, and install it. If you want to go to the trouble, you can get XAMPP, and once it's installed, move the PHP file to the root of your installation (usually c:\xampp\htdocs\ on windows) and then use the url localhost/script.php in your browser.

How to display PHP & HTML source code on a page?

You can use html entities <?php in the html it will be rendered as <?php

You can use htmlspecialchars to encode your code to use html entities.

How do I get the HTML code of a web page in PHP?

If your PHP server allows url fopen wrappers then the simplest way is:

$html = file_get_contents('https://stackoverflow.com/questions/ask');

If you need more control then you should look at the cURL functions:

$c = curl_init('https://stackoverflow.com/questions/ask');
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
//curl_setopt(... other options you want...)

$html = curl_exec($c);

if (curl_error($c))
die(curl_error($c));

// Get the status code
$status = curl_getinfo($c, CURLINFO_HTTP_CODE);

curl_close($c);


Related Topics



Leave a reply



Submit