Zend Certified Engineer (ZCE) Study Guide Links


PHP Basics

Object Oriented Programming

PHP 4/5 Differences

  • Object Orientation
  • E_STRICT – In PHP 5 a new error level E_STRICT is available. As E_STRICT is not included within E_ALL you have to explicitly enable this kind of error level. Enabling E_STRICT during development has some benefits. STRICT messages will help you to use the latest and greatest suggested method of coding, for example warn you about using deprecated functions.
  • References vs. Object Handles | Further Reading

Streams and Network Programming

Security

Functions

Databases and SQL

Strings and Patterns

Arrays

XML and Web Services

Web Features

Design and Theory

Reference

Get the width and height of an image using a function in PHP


This is a very useful function in PHP. PHP provides function to get the width and height of an image. The
getimagesize() function will determine the size of image file including flash file(swf).

Syntax

list($width, $height, $type, $attr) = getimagesize(“image_name.jpg”);

Code

This is a sample code, change image_name to your image name and test it!

<?php

list($width, $height, $type, $attr) = getimagesize(“image_name.jpg”);

echo “Image width ” .$width;
echo “<BR>”;
echo “Image height ” .$height;
echo “<BR>”;
echo “Image type ” .$type;
echo “<BR>”;
echo “Attribute ” .$attr;

?>

When you run this script you will see the result like this

Image width 379
Image height 344
Image type 2
Image attribute width=”379″ height=”344″

You will get the width, height, type of an image and also attribute of an image, I use this function in my image

upload form.

Type of an image you can see from table below You can read a full manual here

Type of the image
1 = GIF      5 = PSD          9 = JPC     13 = SWC
2 = JPG     6 = BMP     10 = JP2     14 = IFF
3 = PNG   7 = TIFF(intel byte order)               11 = JPX     15 = WBMP
4 = SWF   8 = TIFF(motorola byte order)     12 = JB2     16 = XBM

Reset Webmin Password for ubuntu


I found this problem at the first time when webmin installed. Also this happens to everyone at one time or another. You go on vacation and when you come back, you forget all of the passwords on your computer.

I failed logging in several times and then Webmin blocked my IP. Getting localhost blocked isn’t a good thing to see. So I searched the Internet for a way to reset the password and I found this procedure:

1. Login to your computer as root. Type on browser address bar https://localhost:10000/
2. If you are running a Debian distribution (ubuntu), enter the following command:
/usr/share/webmin/changepass.pl /etc/webmin username password
3. Login to Webmin with your reset password.
4. eNjoY!

How to determine if the user is viewing the Joomla front page or not?


If you are using Joomla older version like 1.0 then you’ll only need to verify the current component with the following command:


if ($option == 'com_frontpage' || $option == '') {
echo 'This is the front page';
}

Bellow porsion for Joomla! 1.5 could be easily confirmed by the following command:


if ( JRequest::getVar('view') === 'frontpage' ) {
echo 'This is the front page';
}

Just in case the above command doesn’t work then the issue could be a little more complicated and need to check if the current active menu item is the default one. I saw this issue in some 1.5 early versions.


$menu =& JSite::getMenu();
if ($menu->getActive() == $menu->getDefault()) {
echo 'This is the front page';
}

Ubuntu Linux Start / Restart / Stop Apache Web Server & MySQL Server


How do I start, restart or stop Apache 2 web server & MySQL server under Ubuntu Linux operating systems?

/etc/init.d/apache2 is service script used to start / stop / restart the Apache2 service under Debian or Ubuntu Linux. You need to login as root or use sudo command restart Apache.
sudo -i
Enter your root password
Task: Start Apache 2 Server
# /etc/init.d/apache2 start
or
$ sudo /etc/init.d/apache2 start

Task: Restart Apache 2 Server
# /etc/init.d/apache2 restart
or
$ sudo /etc/init.d/apache2 restart

Task: Stop Apache 2 Server
# /etc/init.d/apache2 stop
or
$ sudo /etc/init.d/apache2 stop

Task: Start MySQL Server
# /etc/init.d/mysql start
or
$ sudo /etc/init.d/mysql start

Task: Restart MySQL Server
# /etc/init.d/mysql restart
or
$ sudo /etc/init.d/mysql restart

Task: Stop MySQL Server
# /etc/init.d/mysql stop
or
$ sudo /etc/init.d/mysql stop

Random password generator with PHP


function generate_password($length='')
{
$str='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_?/:(){}[]0123456789';
$max=strlen($str);
$length=@round($length);
if(empty($length)){$length=rand(8,12);}
$password='';
for($i=0; $i<$length; $i++){$password.=$str{rand(0,$max-1)};}
return $password;
}

In the above code the PHP function generate_password() takes one optional argument, the length of the password. If you do not specify the length then this function will return a random password of length from eight to twelve characters. PHP variavle $str hold the characters to be used to generate password. You can edit this string according to your need.

PHP Fatal error: Allowed memory size of 65498749874 bytes exhausted ….


This error message can spring up in a previously functional PHP script when the memory requirements exceed the default 8MB limit. Don’t fret, though, because this is an easy problem to overcome.

To change the memory limit for one specific script by including a line such as this at the top of the script:

ini_set(“memory_limit”,”12M”);

The 12M sets the limit to 12 megabytes (12582912 bytes). If this doesn’t work, keep increasing the memory limit until your script fits or your server squeals for mercy.

You can also make this change permanently for all PHP scripts running on the server by adding a line like this to the server’s php.ini file:

memory_limit = 12M

Keep in mind that a huge memory limit is a poor substitute for good coding. A poorly written script may inefficiently squander memory which can cause severe problems for frequently executed scripts. However, some applications are run infrequently and require lots of memory like importing and processing a big data file.