GetDotted Domains

Freeola Guides

 

PHP Scripting Essentials

Last updated on by Freeola Support

5 out of 5 people found this article useful.

Welcome to the Freeola Internet customer support pages. This guide is designed to give some general information about PHP scripting. For more internet help topics please visit our main Support Guides Page.

Below is some essential information for using PHP on Freeola's hosting services, and also some examples of more advanced features such as hit counters & php includes.

PHP, which stands for PHP: Hypertext Preprocessor, is an HTML-embedded scripting language which will allow you to create an interactive website without the use of CGI. Guestbooks, 'formmail' and hit counters are just a few things that PHP can handle. To see some examples of what PHP elements you can use, please click here.

Like standard HTML pages, all files are uploaded into your htdocs or public_html directory on the Freeola server.

The Freeola Web Hosting servers run the most up-to-date stable version of PHP, with the option of choosing which recent version best suits your site needs.

For a full list of PHP versions and modules on each of the Freeola web servers please visit the PHP Configuration and Modules page.

PHP File and Folder Permissions

As the Freeola Web Hosting services run the latest version of PHP, permissions on PHP scripts need to be set more securely than they did previously. To change any permissions of any web file or folder Freeola recommends you use an FTP client such as Filezilla.

In order to comply with the new security requirements you must ensure that you follow the guidelines below:

  1. PHP scripts cannot be in a folder that is writable by anyone other than the user.

    The usual permissions for your htdocs folder would be to set them to 755 not 777.

  2. PHP scripts cannot have their permissions set so that they are writable by anyone other than the user.

    The usual permissions for your PHP files would be to set them to 755 not 777.

  3. PHP script files cannot have their permissions set so that they are writable by anyone other than the user.

    The usual permissions for your PHP files would be to set them to 644 not 777.

  4. Some commands such as exec, shell_exec, system and passthru are no longer available.

  5. PHP7 and 8 support is now available on all standard, VIP and SSD Freeola Servers.

  6. Following the upgrade, a change has been made to our PHP configuration to switch register_globals OFF. This basically means that statements such as:

    echo $my_variable_name;

    will no longer function correctly. There is a simple resolution to this problem in the form of some code that should be inserted into the top of your page. Here are some examples:

    If the variable you are trying to access is passed via the URL string:
    $my_variable_name=$_GET['my_variable_name'];

    If the variable you are trying to access is passed via a form post operation:
    $my_variable_name=$_POST['my_variable_name'];

    If the variable you are trying to access is a server environment variable:
    $my_variable_name=$_SERVER['HTTP_HOST'];

Displaying the Date and Time:

You can display the local date and time on your webpage using PHP. Simply copy and paste the following  PHP code into your webpage where you would like the date and time to be displayed:

<?php echo date('D M d, Y H:i:s'); ?>

Don't forget that you must give the page a .php ending for PHP to work correctly (e.g. 'mypage.php').

Including Another File Into Your Web Page

An 'include' is a way of embedding information from a single file into another file. This is particularly useful for multiple web pages which need to show the same piece of information.

Once set up, you then only need to change one file to change that information across all of your pages.

A PHP 'include' statement looks like this:

<?php include('pagename.php'); ?>

You simply insert this code into your web page(s) exactly where you want the information from the source page to appear.

For example, lets say you have a web site and on every page you show a 'quote of the day'. The quote would be saved in a separate file (say 'quote.php') as plain text and then you could use the following code on every web page where you want the quote to appear. Example:

Today's quote is: <?php include('quote.php'); ?>

The source file can even contain HTML code if required. Includes can save you time and effort when it comes to updating your web site so it's well worth a look for anybody wanting similar content on more than a few pages on their web site.

The file that contains the PHP 'include' statement must have a .php extension. The source file can have any name with or without a file extension (e.g. filename.php', 'filename.html', 'filename.txt' or just 'filename').

Random Image Generator

This useful piece of code allows you to display random images on your web site. The images need to be stored in your web space and the code will randomly pick one to display, it is similar to the way that some companies display random adverts on their web pages. All you need to do is edit the PHP file to match your situation, upload it to your web space and then place the line:

<?php include "randomimage.php"; ?>

where you would like the images to occur.

Password protect a webpage

This code allows you to password protect content on a webpage so that the user must enter the correct details before he can view it. All you need to do is name the page (keeping the .php extension) and then edit it in a text editor putting in your chosen username and password in the relevant places. Put the content you want to protect inside the page and then upload. Your page will now be protected.

Download the code here

Password protecting pages within your Freeola hosted website is done quickly and simply if you are signed up for our VIP+ Hosting service. Enabling this service will allow the protecting of any web page within your site via your MyFreeola account.

Both the InstantPro and RQS Builder services also feature in-builder options to enable password protection on individual pages.

Enabling zlib compression

Some content management systems that you may decide use with your hosting may come in a compressed format and offer you an option to extract files on the server using zlib. By default this is not fully enabled on Freeola's hosting servers however can be activated by adding the following lines to a file named .htaccess in the root of your htdocs directory.

php_flag zlib.output_compression on
php_value zlib.output_compression_level 5
Adding a visitor counter

It is also possible to add a visitor counter to your website. To do this, please download the script file linked to below and follow the instructions.

Visitor Counter Script

  1. Either Cut and Paste the code sections of the counter.php file into your existing web page or upload the page with the .php extension (i.e. index.php) into the htdocs directory.

  2. Now create a new directory called count within your htdocs folder.

  3. If you use Internet Explorer, use the FTP link in your MyFreeola account to view the "count" folder. Right click it and choose "properties" then make sure that all the boxes in the "Permissions" section are ticked. Once you have done this your counter should work.

  4. If you do not have this browser then you will need to change the permissions using a compatible FTP client. SmartFTP will work fine, once you have connected then right click on the "count" folder in the main window and select properties/CHMOD. Change the "permissions" number to "777". 

  5. That's it, you should now have a basic counter that records hits to your site!


Did you find this article helpful?


Freeola & GetDotted are rated Five stars

Check out some of our customer reviews below:

View More Freeola Reviews

Need some help? Give us a call on 01376 55 60 60

Go to Support Centre
Feedback Close Feedback

It appears you are using an old browser, as such, some parts of the Freeola and Getdotted site will not work as intended. Using the latest version of your browser, or another browser such as Google Chrome, Mozilla Firefox, Edge, or Opera will provide a better, safer browsing experience for you.