PHP Ternary Operator

PHP ternary operator isn’t beautiful for reading reason

It’s also make confuse, but for the sake of simple it’s OK :-)

Syntax :

( expr1 ) ? ( expr2 ) : (expr3)

If expr1 return true, then it evaluates to ( expr2 )
If expr1 return false, then it evaluates to ( expr3 )

it’s similar to if..else

if(true) {

code 1

}

else {

code2

}

example :

// ternary operator

$year=2006;
$james_bond_title = ($year==2006) ? “Casino Royale” : ” I forgot “;

echo “James Bond Movie Title in 2006 is : $james_bond_title”;

//if … else

if($year==2006){

$james_bond_title=”Casino Royale”;

}

else {

$james_bond_title=”I forgot “;

}

echo $james_bond_title;

Which one is your favorite ?

Recover Your Joomla Administrator Password

Joomla is very popular CMS, it’s easy to setup and require only working php and mysql installation.

A problem may arise when your administrator password lost or forgot.

Can I recover my admin password or create a new one ?

It’s common question in "Setting your own Content Management System" workshop.

Use php md5() function !

Here’s the steps :

1. Open your php ide and type this code :

$my_new_password =’my_joomla_administrator_password’;
$my_md5_password=md5($my_new_password);
echo "My New Joomla Administrator Password is : $my_md5_password";

save this snippet as joomla.php and run it in browser.

2. Copy paste your md5 generated password.

3. Open phpmyadmin and select joomla database.

4. Select user table (jos_users) and find administrator entry, click edit icon.

5. Replace your password with password in step 2

6. Save your changes

7. Done, try login to administrator page with new password.

Year Validation with PHP

This code snippet validate user input from a form :

$year=strip_tags($year);

if(empty($$year) || is_numeric($year) || strlen($year)!=4 || $year

  1. strip all html tags ( handle by strip_tags )
  2. make sure the year in 4 digit (with strlen help)
  3. make sure its number not character (is_numeric)
  4. not empty (php empty function)
  5. force user enter year of birth not less than 1970

More information about those function, read php manual or search from php.net

Regex, nightmare for newbie

Regex (Regular Expression) is nightmare for me, validation email, pattern recognizing task always depend on regex.

A few software out there will help us (newbie) to learn regex faster with “experience mentor”

I like these software :

1. Regexbudy
A lot of video demo
PHP section

2. Regexcouch
For medium level, since I’m totally newbie :-)

Mastering regex book also helpfull, I just forgot the title, but in my amazon wishlist.

I just spend some money for openbsd books :-)

Other good source :

PHP Manual on Regex Section

Happy learning :-)

Oracle XE for network access

Default install of Oracle XE only allow connection from localhost.

For network access you need sysdba access.

Login as “system” with propriate password


Click the arrow near administration tab

Change access into “available from local server and remote connection” and followed by click “Apply Changes”

See confirmation message

Logout and try login from network.