When a PHP page is requested from the server, the PHP code runs before the result is sent to the browser. Thus, there is no URL available in a browser while PHP runs.
Although the URL in the browser's address bar is unavailable, PHP does store values that can be used to construct what the URL will be.
Each of the parts resides in the global $_SERVER variable. This list names them along with a hint about what they contain.
$_SERVER['HTTPS'] (protocol test)
$_SERVER['HTTP_HOST'] (domain & port)
$_SERVER['PHP_SELF'] (relative URL)
$_SERVER['QUERY_STRING'] (URL parameters)
The article describes how to build the full, absolute URL of the current PHP script, which would be the URL of the web page where this article is published.
Some things happen so automatically that we tend not to notice.
The address bar of browsers is an example. When you've loaded a web page and then you tap the URL in the address bar, the editable URL is selected. You can type a new URL without having to erase the old one (it's erased automatically when you begin to type). If you do that a lot, you tend to take the convenience for granted.
It's a bit unhandy when you only want to change something in the current URL (requires an extra tap to deselect). Still, it is easier to unselect with a tap than it is to erase all the data before typing a new URL.
This article describes how to do a "select the field when the field is tapped" for your forms.
If you have wanted a self-contained PHP script for file uploading on your website, here it is.
Optionally, it can be customized to require login.
Tell the script which directory to use for storing uploaded files. Upload the script to your website. You're good to go.
Uploaded files will not overwrite each other. If a file is uploaded with the name of a file already in the directory, the new file gets a number appended to its file name.
Just for fun, let's put a div on the web page that jumps. The div can contain any valid HTML content. For this article, the div will contain an image.
When the mouse pointer moves over the image, the image jumps to a new location. For devices without a mouse, tapping the image makes it jump.
The demonstration image is an outline of an envelope within a colored circle. The image has the word "Possibilities" above the envelope.
If you're using a laptop or desktop computer to read this article, try putting the mouse pointer on the demonstration image. The image will jump to a new location.
On the other hand, if you are using a phone or tablet to read the article, tap the image to make it jump.
When the image jumps, it relocates itself to a random location within the browser window (the viewport). The window can be scrolled, and the image remains at its viewport location.
Fun ideas include an image of a squirrel, a small video playing, the words "May problems elude you", a laughing cartoon face, or an eagle in flight. You're probably thinking of something right now that would be fun on your web page.
This is a techy how-to article about measurements related to div locations and dimensions.
Listing all the reasons to know the information would be a long list. Getting the dimensions of a div element for use when centering the div within the viewport is one reason. It is also how I used it just yesterday.
There are various ways to try to determine the location of a div in the viewport (browser window, generally, but might also be an iframe). Similar to its dimension, there are various ways to determine the width or the height of a div.
The ways are JavaScript methods. PHP doesn't work for this functionality because PHP runs before the web page is loaded into a browser window.
The JavaScript function I prefer to use provides the viewport location and the dimensions of a div all in one function call. getBoundingClientRect is the name of the function.
At Willmaster and some other sites, we use a site-wide One Login System. The system can protect any directory that contains a customizable .htaccess file.
How the One Login System Works
There is one log-in page. After logging in, a cookie is set.
Directories are protected with entries in the .htaccess file. If the cookie is set, the browser is allowed to access the directory. Otherwise, the browser gets a "not authorized" message.
Why?
For Willmaster.com, we use the One Login System to protect various scripts on the domain. The Possibilities emailing software is an example. Others are syndication, web content updating, server monitoring, and backup software.
Some of those are in separate directories. Some share the same directory. So long as the directory has the customized .htaccess file, we're good.
For better security, either or both the username and the password may contain embedded spaces.
The source code provided in this article is an updated version of what we are using. It was updated for easier customization and to allow more than one username/password set to be specified. (With a separate username for each person allowed access, removing a username later won't affect anybody else's log-in.)
If you program in PHP, you know it is a fairly common need to peek into variables and see what they contain. It can be especially needful when one is chasing a bug.
If you have programmed with PHP for a long time, you no doubt have developed ways to view the content of variables without affecting the flow of the software's execution.
Here is another way, or perhaps a way you are already using. This method publishes the variable name, its length, and its content on the web page. The dumped information can be viewed on the web page where the PHP is running.