Archive for the ‘PHP’ category

Flash(AS2) + PHP + MySql

June 26th, 2010

Last couple of month was working on Flash. Became familiar with Flash and started loving it… :) Then a project came they
asked for making CMS for their flash site. You can see the site http://www.zfp.com

And the game started… :)

Started learning AS2 and loadvars. Faced lots of difficulties and finally manged to communicate with Flash(AS2) + PHP + Mysql.
In this post I will try to give basic idea to communicate Flash(AS2) and PHP.

1. Flash(AS2)

lv_th = new LoadVars();
lv_th.onData = function(varText:String)
{
temp = varText.split(‘@@’);
photo= temp[0].split(‘|’);
photo_title = temp[1].split(‘|’);
photo_description = temp[2].split(‘|’);
};
lv_th.load(“photo_gallery.php?gallery_id=5″);

1. PHP+MySql

$gal_id = $_GET['gallery_id'];
$sql = "SELECT * FROM gallery WHERE gal_id=$gal_id ORDER BY gal_id";
$result = mysql_query($sql) or die(mysql_error());
$photo = array();
$photo_title = array();
$photo_description = array();

while($rows = mysql_fetch_object($result))
{
    $photo[]             = $rows->photo;
    $photo_title[]       = $rows->title;
    $photo_description[] = $rows->description;
}
print implode('|',$photo) . '@@' . implode('|',$photo_title) . '@@' .
implode('|',$photo_description);

First one is flash AS2 Code to get the data from php. It first create a new instance LoadVars();

then onload called the photo_gallery.php?gallery_id=5 and wait for the response to come.

In php we made the query based on the gallery_id and get the data and put it in three separate

array. then we implode each array values with ‘|’ and separate each array with ‘@@’.

In flash after getting the data as a string in varText variable we split it by ‘@@’ to separate the

different array values and after that separte it in ‘|’ to get each value. Now we have all the data

in photo, photo_title and photo_description array. Use the array values as you want…. :)

Note: In the data there should not be ‘@@’ or ‘|’. If it contains then you have to choose the separator carefully. Choose a separator which is not come as data.

Have fun with flash + php + MySql….. ;)

GD Star Rating
loading...
GD Star Rating
loading...

Became ZCE

February 3rd, 2010

I am very happy to see my name listed under Bangladesh In Zend Yellow page of ZCE. I passed the exam in first chance. Thanks to Allah and to all previous ZCE of my country. I get inspired mostly from them either by talking with them or by reading their blogs. And of course thanks goes to my class mates and friends. One of my friend is also ZCE (Mahmud Ahsan).

I bought the Zend Exam Voucher on 3rd February 2009. But for so many reasons I was unable to attend the exam and the most big reason is my laziness…:) I rescheduled the exam may be for 50 times but as my laziness comes up so I couldn’t give the exam. 3rd February 2010 is the last date of the exam and if I unable to attend the exam it will expire. So I was in a pressure to give the exam and I attend the exam on 2nd February before one day of expiry Alhamdulillah passed the exam. Now let me share with you what I did to prepare myself. But it may work with you or may not. The way of thinking of the entire human is not the same. So follow what you feel better way to prepare yourself.

First of all as all the ZCE’s will suggest you the same thing to read the
Zend Certification Guide and Use the test exam.

1.  Finish one topic from the Zend Certification Guide and search it in php.net
for details. Quote or write the things which you can use as just quick review. Do it
for all the topics of 1 Chapter and pin it. After that go to the Second Chapter follow
the same thing and review the first chapter at the same time so you won’t forget
the thing. After finishing 12th Chapter you will have 12 clips in your hand for quick review.

2.  Now you will see some of the sub topics of the 12 topics listed in Zend Site which is not
there in Zend Certification Guide. So now you have to go for Google search or php.net to learn those
things and write quotes in your note.

3. After finishing all those things now check out if you missed any subtopics. If you saw that everything is done then fix your mind to give a mock test. But 5 mock tests from zend site and give one test. After that you will realize the type of questions and lake of your knowledge in a chapter. Go now study those chapters again if you got grade pass or fail. After finishing give a second mock test. If you got excellent in all the chapter now you are ready to face the real exam. Schedule the real exam and go for it.

Rather than this you can check the following resource which I followed parallelly.

Some sample Questions Link ( I don’t know this is legal or not. If it’s illigal plz let me know so i will remove the link)
Link 1
Link 2

Review of 12 Chapter Other ZCE’s Blog
Read The Web

The Paul Paul Reinheimer Review Guide is also very useful

Download Link

Check out Frank ZCE Preparation. It also helped me lot.

Frank Blog

Download Frank Hand Note

I cant share anything else as I agreed with zend not to share. But believe me if you
are a PHP programmer for 6 month or 1 years it wont take you more then 12 days
for 12 chapter I mean for zend preparation. Thank you. Best of luck….:)

GD Star Rating
loading...
GD Star Rating
loading...

JeddahGeeks First meetup(Nov,09)

December 6th, 2009

Some of my Jeddah friends Arranged a group called JeddahGeeks. Where Web developer, designer and entrepreneurs can share their knowledge, thoughts and experience. So we can learn something and gain some knowledge from some real geeks. In Our first meet up(13th November) I give a small speech on “How to Become a PHP Geek?”. I am inspired by the event of PHPExperts Seminar of Bangladesh. The presentation of Emran Hasan Brother on How Becoming a kick-ass PHP ninja gave me more inspiration to make this presentation. You can see the presentation below. As this is my first presentation any criticize and suggestion will be appreciated.

GD Star Rating
loading...
GD Star Rating
loading...

FirePHP with FireBug

September 28th, 2009

Last Couple of months I was using Firebugs ad-dons of Fire Fox.  It helped me lot to debug my css. It’s simply great help for me. Today I came to know about new ad-dons FirePHP which can be used with FireBug. You can debug your php code in your browser. It sounds cool. You don’t have to use print_r or var_dump to debug your php code and massed up your site by dumping your array.

It’s great to use it like same as firebug. Hope it will be useful for php programmers.

To use FirePHP you need the following thigs

After installing those three you should download the FirePHPCore from http://www.firephp.org/HQ/Install.htm.

Setup

Let’s assume your document root is /www/ and it is in your PHP include path.

Step 1 Locate the server library

Locate the /lib/FirePHPCore folder in the FirePHPCore archive and move it into your document root.

/www/FirePHPCore/fb.php
/www/FirePHPCore/FirePHP.class.php
/www/FirePHPCore/LICENSE

You can skip this step if you are using PEAR. Make sure the PEAR repository is in your include path.

Step 2 Include the server library

Create a file at /www/Index.php and open it in your editor.

require_once(‘FirePHPCore/FirePHP.class.php’);

Step 3 Start output buffering

ob_start();

Now That’s it. It’s now time to play. Your first Log Message

$firephp = FirePHP::getInstance(true);

$var = array('i'=>10, 'j'=>20);

$firephp->log($var, 'Iterators');

Console_HelloWorld_Screenshot
FirePHP Official Site:  http://www.firephp.org

The Site I got the information: http://sixrevisions.com/web-development/how-to-debug-php-using-firefox-with-firephp/

GD Star Rating
loading...
GD Star Rating
loading...

get image width and height using PHP

February 9th, 2009

Sometime we have to get the uploaded image name from database. But we don’t know the image width and height. Width and height may be variable. But we want to know the actual width and height of an image. We can use getimagesize() PHP function to get the width and height of an image.

array getimagesize ( string $filename [, array &$imageinfo ] )

This function returns an array of 7 elements. Index 0 and 1 contains respectively the width and the height of the image.

Example:

<?php

$image_Name = ‘ekram.jpg’;

list($width, $height) = getimagesize($image_Name);

echo “<img src=’$image_Name’ width=’$width’ height=’$height’ />”;

?>

GD Star Rating
loading...
GD Star Rating
loading...

How to organize PHP Project files?

January 28th, 2009

I am organizing PHP Project files in following way. I don’t know this is standard or not. But it makes my life easier. If anyone knows any standard for organizing PHP files please share with us.


/webroot
/image (all images)
/dev (scripts and images under development – this is a mess)
/doc (document and pdf files that is uploaded or my work description)
/etc (configuration, i.e. database un&pw, etc – restricted perms)
/home (this is where most of the website lives)
/inc (included files)
/func (included functions)
/class (included class)
index.php

GD Star Rating
loading...
GD Star Rating
loading...

Preventing Duplicate Record Insertion on Page Refresh

January 27th, 2009

Most of beginners (including me) face these problems inserting data into database.

When clicking submit button after filluping a form if you refresh the form it will insert the duplicate data. There are two solutions that I know from Google search. May be you can find more by Google search.

And since you cannot avoid a refresh of the screen…

<form action=”insert.php” method=”POST”>
<input type=”text” name=”name”>
<input type=”text” name=”telephone”>
<input type=”text” name=”email”>
<input type=”sumbit” name=”submit”>
</form>

1) If you are doing a form post, you might consider sending a location
header AFTER you inserted the record:

insert.php
// after inserting the data
header(“Location: thanks.php“);
exit();
// do not forget the exit, since your script will run on without it.

In that way your script will process the posting, and then redirects the
browser to thanks.php. This page will contain a message (Thank You). A reload of thanks.php will not result in a fresh db insert.

2) If you’re using sessions, generate serial and supply it as hidden field with
every posting form. Increase it at every post and decline to store data if
serial in the _POST isn’t equal to the one stored in _SESSION.

Combining it with redirects (always good to have such protection), you’ll
probably never got the duplicated submits.

GD Star Rating
loading...
GD Star Rating
loading...

Difference between echo() and print()

January 15th, 2009

1) echo is faster than print. Because echo doesn’t have return parameter like print.

2) print behaves like function where echo not.

3) echo can take multiple parameter where print can’t.

NOTEecho is the prefer method.

GD Star Rating
loading...
GD Star Rating
loading...