PHP Related Questions (28 Articles)

Does Siteground support PHP HTTP Authorization?

Siteground supports the PHP HTTP Authorization and in order to enable it you need to add the following lines to the .htaccess file located in the web site's home folder: RewriteEngine on RewriteCond %{ HTTP:Authorization } ^(.*) RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]…

How to enable zlib compression manually for PHP scripts

PHP Zlib module allows you to transparently read and write gzip compressed files. Thus it is used for serving faster content to the end users by compressing the data stream. Some applications like Pligg require zlib compression enabled by default in the PHP engine. For this purpose you can easily enable it by placing the following line in a local php.ini file: zlib.output_compression = On Please note that this php.ini file has to be copied to each folder requiring the above settings. This is necessary because settings in php.ini files do not apply…

How to install Smarty Template Engine

Follow the steps below to install Smarty Template Engine on your hosting account: Download the latest version from the official website . Extract the package on your computer. Upload the libs folder to your hosting account (for example in the public_html folder) Create a php.ini file and add the following line to it: include_path = /home/username/public_html/libs/ This line defines the include path to the libraries. Change username with your actual cPanel username. Now all you need to do to call the Smarty Template Engine is to include it in your php files with a line such as.: require '/home/username/public_html/libs/Smarty.class.php';…

My script requires ionCube loaders Do you have ionCube installed?

The ionCube loaders PHP extension is installed on all of our shared hosting servers by default. If you want to check the ionCube loaders version, please create a PHP script on your account with the following content: <?php phpinfo(); ?> Then access the file via your browser and it will show you the entire configuration of the PHP interpreter as well as the ionCube loaders version. If you have a script that gives an error about missing ionCube loaders, please make sure you are not using any custom php.ini files. When you have a custom php.ini file, it overwrites the global PHP settings and this may result in a missing ionCube loaders script…

How to generate PDF files with PHP?

FPDF is a PHP class that allows you to generate PDF files without using the PDFlib library. FPDF is free and can be downloaded from the official website’s download section . The download package contains all necessary files, along with some tutorials on how to use it. A basic example of using FPDF is with the following PHP code (you must download and extract the FPDF package in the folder where the PHP file with the code is located): [crayon-57bf5b1164b60895072165/] Let's say that you have downloaded and extracted the FPDF package inside a folder called ~/public_html/ fpdf/ . You can create a new PHP file called toPDF.php inside the same folder and insert the above code. You can then save the file and try to access it through your browser: http://yourdomainname.com/fpdf/toPDF.php Upon execution of the script, a new PDF file will be generated and you will be prompted to download…

How to modify PHP settings without using php.ini files

When PHP is running as a CGI module,  PHP settings cannot be modified through an .htaccess file. If you would like to modify a PHP setting, you would have to use php.ini files. Unfortunately, php.ini files work only on a per-folder basis. In other words, if you would like to apply custom PHP settings to two different folders, you would have to place separate php.ini files in each folder. And when you need to apply custom PHP settings to many folders, placing a php.ini file in each folder can be bothersome. Fortunately, there is a workaround which should apply to most applications. Instead of copying php.ini files recursively, you can specify the needed value only once. Imagine you have a Joomla installation which spreads on many directories. You would like to allow remote file inclusion with the PHP setting allow_url_include . One way is to specify it in many php.ini files across all directories. The other way is to specify it in the main configuration.php file with PHP's function ini_set . The configuration.php file is included in all Joomla scripts and that's why your configuration change will take effect for all Joomla directories. Thus all you have to do is add a line in the configuration.php file which says: ini_set('allow_url_include','on'); Now this PHP directive will be valid for all Joomla subdirectories. Similarly, you can do so for almost any other application. Just make sure that you include the PHP directive in the main configuration…

How to enable error reporting in a PHP script?

There are two ways to enable error reporting in your PHP scripts.   1. You can add the following function in the .php file for which you would like the error reporting enabled:   error_reporting(E_ALL);   2. You can add the following option in the php.ini file for your web site:   error_reporting = E_ALL   Those will enable reporting for all PHP errors. The detailed error_report documentation and various options you can set can be found in the official PHP documentation at:   http://php.net/error-reporting   At SiteGround PHP error reporting is enabled by default for all hosting accounts.…

How to change the timezone for a single PHP file?

You can set a specific timezone for a PHP script using the following function which should be added to the PHP file: putenv("TZ=US/Central"); This is just an example. The full list of supported timezones is available here . You should simply replace "US/Central" with the desired timezone. If you wish to change the PHP timezone on a per-folder basis, please check this article for information how to do it.…

How to check if a PHP function is available on the server?

You can check whether a PHP function is enabled by using the function_exists function in a simple PHP script. For example, if you wish to check whether the fsockopen function is enabled, you can put the following code in a php file: [crayon-57bf5b11652c2731080924/] Then you should open the file in a browser and see the result :) Please note that on SiteGround's servers there are no blocked/disabled PHP…

How to check which PHP version is running on my account?

Thanks to SiteGround's server setup, it is possible to run different PHP versions for different folders in your account. More information on how to do this can be found in this article . In order to check exactly which PHP version is used for a certain folder, you should create a simple php file (for example phpinfo.php) with the following line in it: <?php phpinfo(); ?> Then you should open this file in a browser to see the full PHP information. The path to the file should be: yourdomainname.com/folder/phpinfo.php…

How to include PHP code in .htm/.html pages?

In order to include and execute PHP code in .htm/.html pages, you should set PHP as the default handler for these pages. You can easily do this by adding the following line to your .htaccess file: AddHandler application/x-httpd-php52 .php .htm .html Of course, you should make sure that your PHP code is correct and is placed between the opening <?php and the closing ?> PHP tags.…

How to change the date.timezone value in PHP

If your PHP scripts do not show the correct time, the reason is that most probably your hosting server is in a different timezone. This can be easily resolved by changing a setting in PHP called date.timezone. Depending on your location you can set a specific date.timezone value in PHP using the following option which should be added to your local php.ini file: [crayon-57bf5b116545d276477963/] The above example assumes you'd like to set the timezone for your PHP scripts to US/Central. The full list of supported time zones is available here and you should simply replace "US/Central" with the desired timezone. In this article: How to change the value of a PHP setting you can find additional information on how to change PHP values through cPanel or using a custom php.ini file. Also you can check this article: How to change the timezone for a single PHP file to see how you can set different  date.timezone for a single PHP file. Problems like this and much harder ones are easily solved by SiteGround Technical Support. If you are not already our client, take a look at our web hosting features…

Does SiteGround support PHP 4?

SiteGround supports PHP 4 on all shared servers. In order to change the PHP version for your account, follow these steps. Go to cPanel, File Manager Choose "Web Root (public_html/www)" Create a new file (or open the existing one for editing) called .htaccess Add the following line: AddHandler application/x-httpd-php4 .php .php5 .php4 .php3 …

PHP Error: Cannot modify header information

This is a common PHP error which is usually caused by: - White spaces before or after the PHP start "<?php" or end "?>" tags; - Various problems with the header() statement. Check carefully the code before and at the line of this statement. This error might be hard to troubleshoot in cases where different files are included and all of them have to be carefully expected. An easy workaround is to place a php.ini file containing the following directive: output_buffering = On This php.ini file has to be placed in the directory where the error occurs.…

How to include remote code in Php 5.2

By default remote code inclusion is not allowed in Php 5.2. This is an important security improvement over the previous versions. However, some scripts may require to include remote code in order to work properly. For this purpose create a php.ini file and specify the following line: allow_url_include=on This will change the default Php directive and allow you to include remote code in your scripts. Copy this php.ini file in each directory you'd like to have the setting applied.…

How to submit web forms with PHP

How to create secured web forms using PHP In order to create web forms using PHP you can use the integrated mail() function. It is highly recommended to implement antispam functions in your scripts as well. That is needed to ensure that no undesired messages will be relayed through your account. The following script is a simple "Contact Us" form with three fields: 1. Sender's email address 2. Subject of the message 3. Content of the message [sourcecode language="php"] <?php function spamcheck($field) { //filter_var() sanitizes the e-mail address that is inserted // The FILTER_SANITIZE_EMAIL filter removes all forbidden e-mail characters from the inserted string $field=filter_var($field, FILTER_SANITIZE_EMAIL); //filter_var() validates the e-mail address that is inserted // The FILTER_VALIDATE_EMAIL filter validates the value of the text inserted as an e-mail address if(filter_var($field, FILTER_VALIDATE_EMAIL)) { return TRUE; } else { return FALSE; } } if (isset($_REQUEST['email'])) {//this is a simple check that makes sure the email field not empty //this is the check that uses the validation function to ensure the email address is valid $mailcheck = spamcheck($_REQUEST['email']); if ($mailcheck==FALSE) { echo "You have inserted incorrect email address or have left some of the fields empty"; } else {//send email $email = $_REQUEST['email'] ; $subject = $_REQUEST['subject'] ; $message = $_REQUEST['message'] ; mail("test@siteground.com", "Subject: $subject", $message, "From: $email" ); echo "Thank you for using our mail form! We will get in touch with you soon!"; } } else {//if the "email" field is not filled out the form itself will be displayed. echo "<form method='post' action='contact.php'> Email: <input name='email' type='text' /><br /> Subject: <input name='subject' type='text' /><br /> Message:<br /> <textarea name='message' rows='15' cols='40'> </textarea><br /> <input type='submit' /> </form>"; } ?> [/sourcecode] The email validation function is using two filters (FILTER_SANITIZE_EMAIL and FILTER_VALIDATE_EMAIL) to check the inserted in the Sender's field email address for any forbidden characters and to ensure that the email address is typed correctly. If the email address meets the requirements the script reads the rest of the inserted data in the form and sends it to the administrative email. In all other cases the script will inform the sender that the information he inserted is invalid or not full. In our case the emails are being sent to test@siteground.com and you will have to substitute it with yours. The above script assumes the name of the script is…

Is PEAR included in your Php installations

Yes, the standard PEAR packages are included in all Php installations. If your application requires a certain PEAR package which is not included please check this article: http://www.siteground.com/tutorials/php-mysql/pear_modules.htm …

How to switch to a different PHP version?

SiteGround has implemented a unique server setup that allows each customer to choose which version of PHP to use for his / her account. What is more, the customer can even use different PHP versions for different directories in one and the same hosting account. The PHP versions currently supported are: PHP 5.3, PHP 5.4, PHP 5.5, PHP 5.6, and PHP 7.0. It is really easy to change PHP versions for your website with a web hosting account with SiteGround. All you need to do is follow those step: Log in to cPanel for your account Go to 1H Software section -> PHP Version Manager Navigate to the directory you would like to change the PHP version for (note that the change will apply to sub-directories for it as well) Click on the directory name Select the desired PHP version and click Save That is all. You can find detailed instructions how to manually change the PHP version for your account below: Go to cPanel, File Manager and choose "Web Root (public_html/www)". There create a new file (or edit the existing one) called .htaccess and add the following line: To switch to PHP 7.0 [crayon-57bf5b1165623616888532/] To switch to PHP 5.6 [crayon-57bf5b116562f505431645/] To switch to PHP 5.5 [crayon-57bf5b1165637077415316/] To switch to PHP 5.4 [crayon-57bf5b1165645429056155/] To switch to PHP 5.3 [crayon-57bf5b116564c093586632/]   This setting will apply recursively to all of the subdirectories. In case you'd like to have a different version of PHP in a subdirectory, create a new .htaccess file in it with the directive for the desired PHP version in it. If you want to be able to use different PHP versions on a per-folder basis, you can sign up for a hosting account at SiteGround. We offer the best PHP hosting and our support team is ready to assist you with any PHP questions/problems you may…