Software, your way.
burger menu icon
WillMaster

WillMasterBlog > PHP

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Real Web Page Source Code

When you use a browser's "View Source" menu item (generally also available with a right-click), then you get the source code of the web page.

But which source code? Here are 3 possibilities.

  • The browser won't give you the raw or original source code if it includes any PHP code. To get the source code with PHP code intact, you need to have access to the server to download the file (or have the owner of the web site give the file to you).

  • The browser might give you the actual source code it receives from the server. This would be the web page with PHP already having run and made any changes to the page that it has been told to do. It depends how the browser handles JavaScript-inserted content.

  • The browser might present the source code that results after certain JavaScript has run.

The below script gets the actual web page source code after PHP runs but before JavaScript runs.

<?php
$URL = urldecode($_SERVER['QUERY_STRING']);
echo '<pre style="overflow:auto; white-space:pre-wrap; outline:1px solid black; padding:.5em;">';
echo htmlspecialchars(file_get_contents($URL));
echo '</pre>';
?>

No customization is necessary.

Save the file as sourcecode.php or other *.php file name. Upload the script to your server and make a note of its URL.

To use, type the script's URL into your browser, append a ? character followed by the URL of the web page you want to see the source code of. Load that page and you will see the web page's real source code.

Here is an example of what you might type into your browser's address bar. (The example assumes the script is installed at https://domain.com/sourcecode.php)

https://domain.com/sourcecode.php?https://spamfreeform.com/

The result would be the source code of the index page at the spamfreeform.com domain.

The short sourcecode.php PHP script presents the real thing, the real source code exactly like it would be delivered to a browser.

(This content first appeared in Possibilities newsletter.)

Will Bontrager

Was this blog post helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method


All information in WillMaster Blog articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

Recent Articles in the Library

Database Table Dump

Database Table Dump can be used to view database table information without accessing the domain control panel.

Valid File Name Characters

Most simple printable characters are valid within file names. Some are not.

Image Hue Shift

Shift the hues of an entire image with this CSS rule.

Inspecting HTML Tags

Software to inspect meta and link tags that might have changed after the web page was loaded.

Linked Images in Facebook

Post a URL on Facebook. Facebook pulls in an image and links to that URL. (Probably similar on other social media sites.)

Real Download Link

A download link can tell the browser to download the file for saving on the user's hard drive — instead of displaying it in a browser window.

Characters for Hyphenation

The CSS hyphenate-character property can be used to tell the browser an alternate character or set of characters should be used where a hyphen would be inserted at end of lines.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2025 Will Bontrager Software LLC