Examples, hints, and tips to help you code better in PHP.
-
Get the current URL
If you already know some information about the URL you can use that information to replace the respective part.
Start with an empty path
<?php
$path = "";
?>Check for the protocol (ie. http, cgi)
If you know the protocol is http you can replace this accordingly.<?php
// SERVER_PROTOCOL is in the form "protocol/rev#", this strips the revision
$path .= strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/");
?>Check if secure (HTTPS)
-
Embed PHP into HTML
PHP code can be embedded into any HTML web page by using the
<?php ?>tags.<html> <head> <title>My PHP Page</title> </head> <body> <?php echo "Hello World!"; ?> </body> </html>
Most web servers will only interpret php code in pages with a
.phpfile extension.
