Category Archives: Uncategorized

PHP Adding Comments

Comments can come in very handy and could well save you time if you are working on a complex project with many lines of code or most likely, many files.

Three types of comments you can use in PHP:

<?php    
 
// This is a comment  
 
/* This is a comment and is  
   used for multiple lines  
*/
 
 
# This is a comment  
 
?>

All PHP Scripts on this website are provided by phpscripts4u.com where you can find all the latest PHP code snippets, plugins and libraries.

PHP Determine the Value of Booleans

It is correct that TRUE or FALSE should not be used as constants for the numbers 0 and 1. But there may be times when it might be helpful to see the value of the Boolean as a 1 or 0.

Here’s how to do it:

<?php
$var1 = TRUE;
$var2 = FALSE;

echo $var1; // Will display the number 1

echo $var2; //Will display nothing

/* To get it to display the number 0 for
a false value you have to typecast it: */


echo (int)$var2; //This will display the number 0 for false.
?>

All PHP Scripts on this website are provided by phpscripts4u.com where you can find all the latest PHP code snippets, plugins and libraries.

5 PHP Mobile Scripts

In this post you will find some of pretty cool PHP scripts exclusively for mobile phones. PHP scripts from to detect mobile devices to creating your own mobile phones website! Isn’t that sound interesting?!

1. Mobile phones PHP script

Make your own mobile phones website in a few minutes with this script. Mobile phones database is included in this script and contains more than 3300 cell phones with full technical specifications and photo, from more than 65 mobile phones brands.

2. PHP for Android Project

An open source project to bring PHP to Android platform. PHP for Android project (PFA) aims to make PHP development in Android not only possible but also feasible providing tools and documentation.

3. Mobile content system script ARCHIVE

Put up your own PHP & ASP site selling MOBILE PHONE CONTENT in a few easy steps.

4. Mobile Site

With this script there is no need for you to create a subdomain for your mobile website. This script detects if the visitor is using a mobile device and then shows the right versions.

5. PHP Mobile phone detection

With this class you can easily detect mobile devices. This class is very easy to use and support lots of mobile devices, even the new Mac iPad.

All PHP Scripts on this website are provided by phpscripts4u.com where you can find all the latest PHP code snippets, plugins and libraries.

Joomla PHP Error Reporting Example

Joomla PHP Error Reporting Example

You may have seen the Error Reporting field in your Joomla Configuration Settings, and you may have wondered what it is. Simply the Error Reporting field is responsible for controlling the display of errors on your Joomla website. In this post, we’ll show you some Error Reporting examples you might find interesting…
Error reporting

This setting controls which types of errors are being logged (or displayed on screen when enabled). The following values in your

php.ini

are advised for development and production environments:

    ;Development value (show all errors, except for notices)
    error_reporting = E_ALL | E_STRICT
    ;Production value (show all errors, warnings and notices including coding standards.)
    error_reporting = E_ALL &amp; ~E_DEPRECATED

When developing on Joomla,

E_ALL | E_STRICT

is not the right pick as it generates too many warnings on a fresh Joomla installation. You should just use

E_ALL

instead. See the full list of options here.

This setting can also be changed via your

.htaccess file

, but you can’t use the constants like

E_ALL

there.

Setting the equivalent of

error_reporting = E_ALL

in your

.htaccess

:

    # for PHP 5.3.x
   php_value error_reporting 30719
    # for PHP 5.2.x
   php_value error_reporting 6143
    # lower PHP versions
   php_value error_reporting 2047

Displaying errors

When you are developing on your own computer the easiest thing to do is simply show the PHP errors on screen. However, it is not wise to do the same on live websites, because PHP error messages can contain usernames, passwords, paths to files and other sensitive information.

Fortunately PHP has the option to log errors to a file. This way you can keep track of PHP errors that occurred without visitors being able to see those errors.

To enable this feature, choose the following settings in your

php.ini

:

    # Do not display errors on screen,
   display_errors = off
    # but do log the errors that occur
   log_errors = on
    # to the following file:
   error_log = /var/log/phperrors.log

If you set the error_log value to syslog then PHP will send any errors to system logger. This means that on Windows platforms, your errors can you viewed using the Event Viewer.

If in case you don’t have access to

php.ini

, then you can set these variables via your

.htaccess file

.

    php_value display_errors 0
    php_value log_errors 1
    php_value error_log /full/path/to/your/directory/testlog.txt

Choose the location of your log file carefully. It is advisable to place the file outside your so called wwwroot (the folder accessible from the web) to ensure that it cannot be read by other Internet users via a web browser or otherwise.