Home Flash & Swish Flash Tutorials Intro to PHP & Flash

Intro to PHP & Flash

Author: Phil Author's URL: www.webwasp.co.uk More by this author

This tutorial gives you some basic infomation about PHP and how to setup PHP to work with Flash.

Flash can read information stored on-line but cannot write information to a remote server. To write data to a remote server (a place where web pages are stored) you need a server side scripting language. PHP is such a scripting language. PHP not only enables you to create Dynamic Content but enables it to be saved automatically so that next time that web page is viewed it not the same as the previous viewing but now contains the new information.

Dynamic content simply means something which changes. A hit counter is a simple form of Dynamic Content. Every time the page is loaded the number goes up by one and this new updated number is then saved. A Forum or Bulitine Board would be an advanced example of how PHP could be used to create web content. Every time you return to the Forum or refresh a Forum page the PHP will display the new messages.

The Forum on this site is built with PHP and the messages are saved via a PHP to a database. Every time you visit the Forum the PHP reads the database to see what to display on the web page. These pages are dynamically created every time you visit the forum.

PHP is free to use and the goal of the language is to allow web developers to write dynamically generated pages quickly. Hence it has become extremly popular and one of the most used lauguages on the web. It is an extremely versitle and powerful languge.

PHP can be used in conjunction with Flash or it can be used to display data directly on a web page. So PHP is not specifically a Flash technology, it is just that you are able to access PHP via Flash.

  • Flash is the Front End: The bit that you see.
  • PHP is the Back End: The bit that does all the inviccsible back stage work.

Some alternatives to PHP are Microsoft's ASP/VBScript/JScript system, Macromedia's ColdFusion system, Sun Microsystems' JSP/Java system, and the CGI/Perl system.

Example of Flash - PHP hit counter as explained in the next tutorial: Flash PHP Hit Counter

Note: To test the hit counter above press the Refresh Button at the top of your Browser: image 1  (Usually F5).

The count number should go up by one.

Step one: A PHP Enabled server

Note: If you already have a PHP enabled server skip this step.

Flash runs in the Browser. This is why the viewer has to have the Plug in to be able to see the Flsh Movie. Most web Browser now come with the Flash Plug In already installed. The point is that it is the Browser on the viewers local computer that is doing all the work. This is why Flash cannot save file to the web server - it is not running on the server but on the users computer. The users computer is called the Client as opposed to the Server.

PHP is a Server Side Script. This means that the script runs on the web server before the browser reads the web page.

So PHP works like this:

  1. Client requests a web page with PHP content.
  2. Server runs PHP script.
  3. PHP script dynamically creates data requested.
  4. Web page reads this data and displays the web page.

Important: Check to see if your Remote Server is PHP Enabled

Before you can use PHP you need to make sure your web server is PHP Enabled. Without this you cannot run the PHP script. Almost all web providers will offer a PHP Enabled Server. So before you do anything check that your provider offers this service. Some web providers offer this by default and other you have to request for them to enable (or activate) it before you can run any PHP script. Some providers may charge you a small amount to do this.

Step two: Viewing File Extensions on a PC

Note: If your computer is already set so that you can see file extentions skip this step.

To be able to use PHP effectivly I recomentd that you set your PC (see note on Macs below) so that yuo can see the file extentions. That way you can easily tell what file is PHP, what file is a Text file, what file is a web page etc.

To be able to see what you are doing you will need to make sure your PC is set so that you can see the file extensions. That is the letters which follow the file name and tell the computer what type of file you are looking at. For example:

image 2

By default when you buy your computer these file extensions are hidden. But to complete this tutorial you will need to be able to see these.

In a PC:

  1. Either right click on the Windows Start Button and select: Explore
    or open: My Computer
    or open: Windows Explorer

  2. Go to: Tools > Folder Options > View (Tab)

    Note: In some older version of Windows you may find Flolder Options under a different Menu such as: View > Folder Options > View

  3. Scroll down until you see: Hide extensions for known file types
  4. Remove the tick:

    image 3

  5. Click: OK
  6. Close the: Program

In a Mac

I am no Mac expert but from what I understand Macs do not use the same file extension system. Adding the three character extension to a Macintosh file name does not hurt on the Macintosh, it has no effect. But it does make moving files to PC (or web server) easier.

Step three: CHMOD Settings

CHMOD stands for: Change Mode

By default files that you upload to your web server are set to read only. That means that someone viewing the page can read it (or more accuratly the Browser reads it) but not change it. You can only change the files on your web server if you have an FTP program and you have the correct access rights such as the correct Password and User Name

For the PHP script has to be able to both open and save files on the server. If the PHP cannot do this ther is not much point in having a server side scripting language. This is where the CHMOD settings come in. CHMOD setting enable yuo to set specific files as readable and writable. CHMOD setting are usually refered to by a code. The default setting for web pages is: 644

Default CHMOD Setting.

For a PHP script to be able to read and write (save) a file you will need to be able to change the CHMOD setting for specefied files to: 666

CHMOD set to 666 so that the PHP script can save the file.

CHMOD and Web Providers
Some web providers may have an on-line FTP program that enables you to select a file and chagne its CHMOD settings. Most web providers will not offer this service!! But no harm in asking.

CHMOD and Web Editors
Some Web Editors will allow you to view your online files and change a specific files properties such as the CHMOD settings. Most web editors will not allow you to do this!! Even sphisticated top of the range web editors like Dreamweaver will not let you change the CHMOD settings. But there is no harm in looking. Open any web editors that you may have on your computer and look up CHMOD in the help menu.

CHMOD and FTP Programs
You guessed it: Many FTP progarms do not let you chagne the CHMOD settings but many do!! Again if you have any FTP programs installed on your computer open it and check the Hekp menu. If you don't have an aproapriate FTP program you can download one from the Internet. Before downloading and installing an FTP program try ans look at the program notes as many FTP programs do not allow you to set the CHOMOD properties.

The FTP program that I use to set the CHMOD file settings is: SmartFTP This program is free to educational and personal users and in my opinion is a very good program but a bit fiddly to set up and use the first couple of times.

As with all FTP programs they enable you to see your files on line like this:

Online files in Smart FTP.

To set the CHMOD I simply need select the file I want to change then right click and select CHMOD. A dialoug box appears similar to the one above. To see a Movie of how to change the CHMOD settings in Smart FTP: Demo (large file).

There are loads of other FTP programs and many are free but it is hard to find a frebie FTP program that allows you to change the CHMOD settings. If the program above is not sutiable you may want to so a search Tucows as they have an excellent selection of freeware and shareware: www.tucows.com

Setting Up your FTP Program
An FTP (File Transfer Protocole) program is a file mangagment system and is not that different to somthing like My Computer or Windows Explorer. Except that it enables you to manage files which are stored on a Remote Server such as a Web Server. Some years ago you needed to have an FTP program to move (upload/download), delete and rename your web files to and from your your local computer to your web site. This capability is now usually built into most web editors. So for example you can now do most remote file managment tasks directly from a program like Dreamweaver.

Like web editors an FTP program not only needs to be installed but it has to be set up. After installation you will need to set up the FTP program to link to your web site. For this to happen you need three bits of information:

  • Password
  • User Name
  • Host Address

If you do not know these three things ask your web provider as they will know.

Using an FTP Program to set the CHMOD
Once you have set up the FTP program correctly you will be able to upload files to your web space and view the files that have been uploaded. It does not matter if you continue to uplaod your files form your web editor or use the new FTP system. What is important is that once they are uploaded that you can see the files. Once you can see the files you can select the file/s that you wnat to change the CHMOD settings on and either right click and go to CHMOD or find CHMOD in the menu stytem. You wil then find a dialog box that will enamble you to change the read/write settings for the selected files:

CHMOD Dialog box.

That is all there is to it.