20 February 2008

SAM History n Hacking | Win Xp administration Hack

1-Introduction
This article introduce very simple way to get Administrator like account and do the job and after finish recover your way, after that Get Admin Password later in your home by Cracking, After get the Admin Password Create a hidden user account and do all your jobs free, and Explain how to make a USB Storage Device Bootable corresponding to any system boot, and how to bypass Mother Board password by Default Passwords, and how to extract it if you are in the system

2-To Hackers / Security Systems Engineers


First All must know that both Hackers / Security Systems Engineers Are 2 faces to the same coin Any way, I try this on Windows XP SP2 I want all to try it on Windows Server 2003, Windows Vista Any Windows NT and POST a Message to make all know what versions exactly this idea can apply for
3-Close Look to hole
Microsoft stores all Security Information in many files but the main file is the SAM file (Security Accounts Manager)! this file contain critical information about users account you can explore the folder
$windir$\system32\config
You will find all things and may discover some thing new, but what amazing here is that the file is available, so we can apply our idea
shot1
You will Not be able To copy them Under XP
4-Dose Microsoft Know and Why!?
Yes Microsoft Know all things, and done on purpose why? I always for many years ask my self why Microsoft doesn’t do real security on their systems from the CD setup to all security aspects In the system, I found(my opinion may wrong)that they need to achieve 2 strategic things

1-They need their software spread and all depend on it and in one day when they feel that they are the One The security will done and all money will go to One Pocket

2-They Forced/Like to Make Some Organizations Hack other systems

Proof:
They can make this File SAM Unavailable by storing the information in FAT, FAT32, NTFS Areas (Sectors reserved by The Operating SYSTEM to Store the Addresses of the files on the HardDisk File Allocation Table) So that it is hard to extract. But they don't!!!!!
5-Understand the Idea
The Idea is simple I will explain it manually and it can then be programmed it is so easy here is the idea

The SAM file is available and the SAM file contain a Security Information, so I created a Free Windows XP SP2 Logon account (Administrator Account without password) that means when windows Lunch it Will enter directly to the system without asking about any password And windows will store this Account in The SAM file on My PC So the SAM file on My PC contain an Account will Make you enter Directly to the Windows, so I will take My SAM File and Replace (by renaming, we will need the original file to recover our way) It with the other SAM File in The Other System or Machine So When you restart It will make you enter directly to the Windows With Administrator Like Account ,do what you need and then back all things to the previous state. All These Steps will be under other system bootable DOS, Knoppiex, Windows Live CD, Because Windows XP will not make u able to copy the Files
6-Get Admin Like Account (The Simple Way)

1- Download My 2 SAM files I Include them in Downloads
2- Go to the target Machine , and try to Access it and Boot from any device CD-ROM, Floppy, NIC if it haven't any of those Read Hint 9
3- After Get Access to the Boot Command prompt c:> or Boot Live OS CD, Go to the windows folder $windir$\system32\config And Copy the SAM File and System File (we will need it later) To other folder, Then go to $windir$\repair copy SAM file
And then Rename the 2 SAM Files to SAM1 in their original places
4- Copy My SAM/config File and Paste it in the windows folder $windir$\system32\config Copy My SAM/Repair File and Paste it in the windows folder $windir$\repair (may this step not required)
5- Reboot and Make windows enter Normally
6- Yeah, No You are in The System
7- Copy the files in step 3 to Floppy Disk or Flash Stick Or Send it to your mail via Internet
8- After finish repeat step 2 and delete My SAM files and Rename Both SAM1 to SAM
9- Reboot , Congratulation you recover your way
7-Crack the SAM-Know the real Admin Password and Apply Hint 8
There is many ways I will introduce 2 ways and explain 1 After you get the SAM File and System File there are Programs That extract the Accounts and their passwords, depending on the idea of cracking the HASH (the HASH is one way encryption method) so that The program will generate random passwords and convert them to HASH and then compare it with the HASHES in the SAM File , so it may take a long time but for fast you will pay more money for ready made HASHES with their user names and passwords the 2 program are

1-L0phtcrack v4.0 (LC4 alternate name) the most famous on the NET
2-SAMInside http://www.insidepro.com/I include on the Downloads

I will explain fast SAMInside

shot1

This is the main window press Ctrl+O or by mouse click Import SAM and SYSTEM

shot1

Window will open to import the 2 files and the program will start to crack the Accounts and get them, and then display users names and their passwords

Any other tool will do the job try all and select your best I Explain here SAMInside because he give me results with 6 character only password and get it FAST
8-Creat a Hidden User Accountn
Windows NT / Windows 2000 and Windows XP has a security setting to hide accounts from the Logon Screen/Control panel users accounts

shot1
Press
Ctrl+Alt+Delet
Give you another Access Dialog


Steps:

1-After getting Admin Password enter to the system
2-create an Account with password
3-click start - > Run - > type Regedit press Enter
4-Go to
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\ CurrentVersion\Winlogon\SpecialAccounts\UserList

shot1


5- Create a new DWORD Value on the UserList
6-Name it with Name of Account to be Hidden
7-set the Value Data of this DWORD Value to 0 to hide it /1 to appear it
8- close Regedit and Reboot
9- Press Ctrl+Alt+Delete when logon Screen Appear another login dialog appear type You hidden user name and password and press Enter

Note:

1- the account profile will be visible in \Documents and Settings, But it will be hidden from Logon Screen and User Account in the control panel

2-there is other method that Inject your Account directly to the Admin SAM without know the Admin Pass, but believe me you don't Expect the result, so if you want try it (if the password hard to get)
9-USB Boot for FAT32, NTFS or any File System

HP Always amazing me to do this we need 2 tools

1- HP USB Disk Storage Format Tool v 2.0.6 I include in Downloads If u want to find more go to http://www.hp.com/
2- NTFSDOS Professional Boot Disk Wizard I include in Downloads If u want to find more go to http://www.winternals.com/

shot1

Just connect your USB Storage
steps:
1- Prepare a Startup Disk or Startup CD , Or any Equivalent
2- In the HP tool select the Device->your USB Storage
3- Select File System FAT or FAT32
4- Check "create a DOS startup disk" checkbox and then select option "using DOS System Files Located at"
5- brows your location
6- Click Start
7- Now you have a Bootable USB Storage Device
8- Now in the NTFSDOS Professional Boot Disk Wizard follow the wizard and you will get a NTFS bootable USB Storage

Why we need NTFS ?
If the Partition of the Windows System is NTFS so with normal Startup you will not be able to access any files because the File System is not Recognized by MS-DOS when we install NTFSDOS Professional on the bootable disk it will allow you To Access any File Under NTFS

Note:
Make sure that the option in Mother board Setup of First Boot "USB-Hard Disk" if you want to boot from a USB
10-Mother Boards Default Passwords and how to extract it if you are in The system

This subject is huge I try to find simple or clever way but as u know many PC's many machines many bios versions and updates so I search the net for the best and I list below ,but if this doesn’t help I recommend you to find the bios version and the motherboard and search the net on Google, yahoo, yahoo groups and other you will find some thing help u

HOW TO BYPASS BIOS PASSWORDS
http://www.elfqrin.com/docs/biospw.html

Removing a Bios - CMOS Password
http://www.dewassoc.com/support/bios/bios_password.htm

How to Bypass BIOS Passwords
http://www.uktsupport.co.uk/reference/biosp.htm

How to Bypass BIOS Passwords
http://www.i-hacked.com/content/view/36/70/

Default Password List
2006-04-30
http://www.phenoelit.de/dpl/dpl.html

Award BIOS backdoor passwords:
ALFAROME--------BIOSTAR--------KDD--------ZAAADA-------- ALLy--------CONCAT--------Lkwpeter--------ZBAAACA-------- aLLy-------- CONDO--------LKWPETER--------ZJAAADC-------- aLLY--------Condo--------PINT--------01322222-------- ALLY--------d8on--------pint--------589589-------- aPAf--------djonet--------SER--------589721-------- _award--------HLT--------SKY_FOX--------595595-------- AWARD_SW--------J64--------SYXZ--------598598 AWARD?SW--------J256--------syxz-------- AWARD SW--------J262--------shift + syxz-------- AWARD PW--------j332--------TTPTHA-------- AWKWARD--------j322-------- awkward

AMI BIOS Backdoor Passwords:
AMI--------BIOS--------PASSWORD--------HEWITT RAND-------- AMI?SW--------AMI_SW--------LKWPETER--------CONDO

Phoenix BIOS Backdoor Passwords: phoenix--------PHOENIX--------CMOS--------BIOS

Misc. Common Passwords
ALFAROME--------BIOSTAR--------biostar--------biosstar-------- CMOS--------cmos--------LKWPETER--------lkwpeter-------- setup--------SETUP--------Syxz--------Wodj
Other BIOS Passwords by Manufacturer
Manufacturer--------Password
VOBIS & IBM-------- merlin
Dell--------Dell
Biostar-------- Biostar
Compaq--------Compaq
Enox--------xo11nE
Epox--------central
Freetech--------Posterie
IWill--------iwill
Jetway--------spooml
Packard Bell--------bell9
QDI--------QDI
Siemens--------SKY_FOX
TMC--------BIGO
Toshiba--------Toshiba
Toshiba--------BIOS


Most Toshiba laptops
and some desktop systems will bypass the BIOS password if the left shift key is held down during boot
IBM Aptiva BIOS
Press both mouse buttons repeatedly during the boot

by rahuldut1
Readmore »»

Speed Up Internet Explorer (IE) Hack

even if IE is not preferred browser today, in fact some of the windows user still using this browser, below is the way to speed up the IE
This is a compilation for the legendary Internet Explorer.. which is the most frequently used browser .

internet Exporer Tricks: Rahul

INTERNET EXPLORER Speed up STARTUP .



I
sn't it annoying when you want to go to a new website, or any other site but your homepage, and you have to wait for your 'home' to load? This tweak tells Internet Explorer to simply 'run', without loading any webpages. (If you use a 'blank' page, that is still a page, and slows access. Notice the 'about:blank' in the address bar. The blank html page must still be loaded..). To load IE with 'nothing' [nothing is different than blank]:

1. Right-click on any shortcut you have to IE
[You should create a shortcut out of your desktop IE icon, and delete the original icon]
2. Click Properties
3. Add ' -nohome' [with a space before the dash] after the endquotes in the Target field.
4. Click OK
Fire up IE from your modified shortcut, and be amazed by how fast you are able to use IE!

~ cheers ~ (it works)


INTERNET EXPLORER SPEED UP.



Edit your link to start Internet Explorer to have -nohome after it. For Example: "C:\Program Files\Internet Explorer\IEXPLORE.EXE" -nohome
This will load internet explorer very fast because it does not load a webpage while it is loading. If you want to go to your homepage after it is loaded, just click on the home button.


or


Open registry editor by going to Start then >> Run and entering >> regedit.

Once in registry, navigate to key.

HKEY_CURRENT_USER\Software\microsoft\Windows\CurrentVersion\InternetSettings. Right click @ windows right > New > DWORD.

Type MaxConnectionsPerServer > You can set value (the more higher the no, the more good speed u get, e;g : 99). [99 in hexa so 153 in binary]

Create another DWORD >type MaxConnectionsPer1_0Server. Then put a high value as mentioned above.

Restart I.E and you are done.


SPEED UP BROWSING WITH DNS trick.!!



when you connect to a web site your computer sends information back and forth, this is obvious. Some of this information deals with resolving the site name to an IP address, the stuff that tcp/ip really deals with, not words. This is DNS information and is used so that you will not need to ask for the site location each and every time you visit the site. Although WinXP and win2000 has a pretty efficient DNS cache, you can increase its overall performance by increasing its size. You can do this with the registry entries below:



Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters]
"CacheHashTableBucketSize"=dword:00000001
"CacheHashTableSize"=dword:00000180
"MaxCacheEntryTtlLimit"=dword:0000fa00
"MaxSOACacheEntryTtlLimit"=dword:0000012d



make a new text file and rename it to dnscache.reg. Then copy and paste the above into it and save it. Then merge it into the registry.


START Internet EXPLORER WITH EMPTY BLUE SCREEN.!!



Set your default page to about:mozilla and IE will show a nice blue screen upon startup.


FIX IE 6 SLOWDOWNS AND HANGS.



1. Open a command prompt window on the desktop (Start/Run/command).
2. Exit IE and Windows Explorer (iexplore.exe and explorer.exe, respectively, in Task Manager, i.e - Ctrl-Alt-Del/Task Manager/Processes/End Process for each).
3. Use the following command exactly from your command prompt window to delete the corrupt file:
C:\>del "%systemdrive%\Documents and Settings\%username%\Local
Settings\Temporary Internet Files\Content.IE5\index.dat"
4. Restart Windows Explorer with Task Manager (Ctrl-Alt-Del/Task Manager/Applications/New Task/Browse/C:\Windows\explorer.exe[or your path]) or Shutdown/Restart the computer from Task Manager.


SPEED UP WEB BROWSING.



Iv'e personally found a dramatic increase in web browsing after clearing the Windows XP DNS cache. To clear it type the following in a command prompt: ipconfig /flushdns.

ALLOW MORE THAN 2 SIMULTANEOUS DOWNLOADS ON IEXPLORER 6.
This is to increase the the number of max downloads to 10.
1. Start Registry Editor (Regedt32.exe).
2. Locate the following key in the registry:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings
3. On the Edit menu, click Add Value , and then add the following registry values:
"MaxConnectionsPer1_0Server"=Dword:0000000a
"MaxConnectionsPerServer"=Dword:0000000a
4. Quit Registry Editor.


IPV6 INSTALLATION FOR WINDOWS XP.



This protocol is distined to replace the Internet Protocal Version 4 used by Internet Explorer it uses hexadecimal ip addresses instead of decimal example (decimal ip 62.98.231.67) (hexadecimal IP 2001:6b8:0:400::70c)
To install To install the IPv6 Protocol for Windows XP:
Log on to the computer running Windows XP with a user account that has local administrator privileges. Open a command prompt. From the Windows XP desktop, click Start, point to Programs, point to Accessories, and then click Command Prompt. At the command prompt, type: ipv6 install
For more information on IPv6, visit the site below:
CODEhttp://www.microsoft.com/windowsxp/pro/techinfo/administration/ipv6/default.asp


ANOTHER WAY TO FIX IEXPLORER 6 SLOW PAGES LOADED.



Here's an easier way to get to index.dat file as addresse in another tweak submitted here.
1. click on Internet Explorer
2. go to to your root dir (usually C:)
3. open Documents and Settings folder
4. open "your username folder"
5. open UserData
6. **close IE if you have it open**
rename index.dat to index.old
logoff and log back on (don't need to restart) open up IE and go to a web page or site that always seemed to load slowly. It should load a lot more quickly now. NOTE. Always rename or backup .dat or other system files before deleting.

Disable Right Click!!


[HKEY_CURRENT_USER\Software\Policies\Microsoft\Internet Explorer\Restrictions]
"NoBrowserContextMenu"=dword:00000001

Enable Right Click!!


[HKEY_CURRENT_USER\Software\Policies\Microsoft\Internet Explorer\Restrictions]
"NoBrowserContextMenu"=dword:00000000


do u want to save entire Page For offline viweing??


Saving Web Pages with Internet Explorer 6

Occasionally, you may want to save an entire Web page on your computer (text, hyperlinks, graphics, and all). To save the Web page that currently appears in Internet Explorer, choose File-->Save As to open the Save Web Page dialog box shown in the following figure. Select the folder in which you want the page saved and then click the Save button.
After saving a Web page on your hard drive, you can open it in Internet Explorer and view the contents even when you're not connected to the Internet. If your motive for saving the Web page, however, is to be able to view the content when you're not connected to the Internet, you're better off saving the page as a Favorite marked for offline viewing. That way, you can decide whether you want to view other pages linked to the one you're saving and you can have Internet Explorer check the site for updated content.
You can also e-mail a Web page or a link to the page to a colleague or friend. To send the current Web page in a new e-mail message, click File-->Send-->Page by E-mail on the Explorer menu bar and then fill out the new e-mail. To send a link to the page instead, click File-->Send-->Link by E-Mail. To create a desktop shortcut to the Web page, click File-->Send-->Shortcut to Desktop.


~ all of them are tested ! ~


Alternate trick


Before performing these steps you need to test your broadband speed
you can test your speed at http://www.2wire.com/
The broadband connection speed can be increased by clearing the route from modem to server. Number of packets sent by modem to server should be increased.Internet speed can be increased by increasing more number of incoming and outgoing packets.The main reason why your internet connection is slow is because of harmful virus.If your system is infected with virus your number of incomming packets will be decreased.This leads to your slower internet speed.Internet speed can be increased by by clearing the route to the server.
This can be done by upgrading costly sofwares and hardwares.This will optimize your system speed.And Increase your system speed.Internet tweak is the best software which increases your system speed for further applications.Another software Windows power tools which makes windows faster and increases your internet speed.And decreases downloading time.It optimizes LAN,CABLE,DSN etc.Another software "internet cyclone"which increases your internet speed from 64kbps to 120kbps.
This tip is designed for increased BROADBAND speed in Windows XP while using standard Network Interface cards (NIC) that are connected to ADSL modems, or when using any directly-connected USB ADSL modem.

To speed up the Internet connection speed we need to configure a special buffer in the computer's memory in order to enable it to better deal with interrupts made from the NIC or the USB modem.

This tip is only recommended if you have 256MB RAM or higher.

Step #1 - Identify the IRQ used by the NIC/USB modem

1. Open the System Information tool by running MSINFO32.EXE from the Run command.

2. Expand System Summary > Hardware Resources > IRQs.

3. Look for the listing made for your NIC (in my case - a Intel® PRO/100+ Management Adapter). Note the IRQ next to the specified line (in my case - IRQ21).

In case of USB modems you will first need to find the right USB device used by your modem. Follow these steps:

1. Open the Device Manager tool by running DEVMGMT.MSC from the Run command (or by right-clicking My Computer > Hardware tab > Device Manager button).

2. Scroll down to Universal Serial Bus controllers and expand it.

3. Right-click the USB Root Hub and select Properties. Note that you might need to do so for all listed USB Root hubs (if there are more than one) in order to find the right one.

4. In the Power tab, look for your USB ADSL modem.

5. In the Resources tab look for the assigned IRQ (in this case - IRQ21).

6. This is the IRQ we're looking for.

Note: IRQs and modem names might vary...

Step #2 - Modify the system.ini file

1. Run SYSEDIT.EXE from the Run command.

2. Expand the system.ini file window.

3. Scroll down almost to the end of the file till you find a line called [386enh].

4. Press Enter to make one blank line, and in that line type IRQX=4096 where X is the designated IRQ number we found in step #1, in my case it's IRQ21.

Note: This line IS CASE SENSITIVE!!!

5. Click on the File menu, then choose Save.

6. Close SYSEDIT and reboot your computer.

Done. Speed improvement will be noticed after the computer reboots.

by rahuldut1
Readmore »»

19 February 2008

5 FAQs To Show You How To Choose A Good Domain Name

Registering a domain name for the first time? I assume you have many questions in your mind. In this article, let us go through 5 FAQ on how to choose a good domain name.

1) What domain name should I choose?

You should choose a domain name that is meaningful. For example, if you are going to build an information site about gorilla, naturally, you should register “allaboutgorilla.info” instead of “allaboutmonkeys.info”.

However, if you are building an information website about different types of monkeys, the “allaboutmonkeys.info” is preferred. In fact, when you are writing about gorilla, you can simply name the page as “allaboutmonkeys.info\gorilla.html”.

2) Should I choose a long or short domain name?

Generally, a shorter domain name is preferred over a long domain name because it is usually easier for people to remember. For example, if you are selling mobile phones, you will want to register “newmobilephones.com” instead of “averygoodnewandcheapmobilephone.com”.

Of course, there are always exceptions. For example, if you are selling rackets, you will want to register “topqualityrackets.com” instead of “tqr.com”. In this example, the former domain name is definitely more memorable.

3) Is there any legal issues that I should be aware of?

That is a very good question. There are certain terms that are trademarks. You should not try to register them. For example, you should try to avoid domain name like “delll.com”. If you are unsure, consult a professional who is qualified to give you legal advice.

4) Should I use hyphen in my domain name?

I would advise you not to use hyphen if you can avoid it. Why? Well, let us consider “ilovecoffee.com” and “i_love_coffee.com”. Generally, when people are searching for a domain name, they will usually type in the domain name without the hyphen first. Therefore, instead of visiting your site, they may end up in your competitor site instead.

However, if your desired domain name is already registered, then you may have to use the hyphened version instead. Alternatively, you may want to approach the owner to see if it is available for sale. You may be able to get it for a good price. Who know?

5) Should I register a “.com”, “.net” or “.info”?

In most situations, a “.com” is the best choice because when people are searching for a domain name, they will usually try “.com” first. This is normal as “.com” is a popular extension.

However, there are always exceptions. For example, if you are registering a site for an education institution, naturally, you will want to register “.edu” instead of “.com”. That is because in this scenario, when people are searching for educational site, they will search for “.edu” first instead of “.com”.


Lubano Lim is a Netpreneur who enjoys marketing on the Internet.

Looking for home based internet business opportunities? For a very limited time, discover the secret system used by many ordinary people to attract thousands of targeted prospects without any cold calling.

Visit http://kingofsponsoring.com now for a free 7 days Boot Camp.

This article is free for republishing
Source: http://www.a1articles.com/article_472564_1.html
Readmore »»

Getting Started With A Cheap Web Site Design And Hosting Service

The exhilaration level of signing up with a cheap web site design and hosting service and seeing a personal domain name come back as approved can be incredibly high. Business owners and individuals alike often feel a sense of euphoria when they realize their own site is about to go onto the World Wide Web. Unfortunately, this sense of amazement often turns to feelings of dread as newcomers to the web site design and operating field have no idea what to do next.

The fact of the matter is that domain name selection and registration is only the first part of the process of getting a web site online. If a cheap web site design and hosting company has been selected to handle the site, chances are would be site operators are sitting on a goldmine of tools that can help them take the next steps in relative stride. Make no mistake though – web site creation and publishing is serious business.
This is especially so if a person hopes to generate income from a site. What happens after the registration can make or break the effort.

Cheap web site design and hosting deals have to be taken to the next level for anything to happen. This means site name owners need to follow a basic process to create their sites, load them with content and publish them to the web. Until this is done, a domain name is nothing more than a letters on a page. To get the ball rolling, it helps for site owners to:

  • Carefully consider their focus. If making money off a web site is the real desire, focus should very likely be rather targeted. This can help with content development and keyword selection. If, for example, the site will be dedicated to affiliate programs, select with care. Joining a program that sells chocolate and one that sells video games can result in site content that makes no sense. Joining a chocolate affiliate program and a gourmet dessert delivery company's affiliate program can work very well together. Do sit down and brainstorm focus, desired content and even looks before moving forward. These decisions will help determine how best to proceed with the actual site construction. Cheap web site design and hosting deals can make participating in affiliate programs very rewarding, but the ultimate success depends on the site owner's ability to focus and market a site.


  • Site construction. Once the focus for the site has been decided upon, the next steps in launching a cheap web site design and hosting domain are generally the most fun and tedious all at the same time. It is here where the site will need to be constructed. Use provided web site building tools if possible or even templates. Just keep the focus of the site in mind. A background of tire treads and neat trucks, for example, doesn't lend itself to a site dedicated to chocolate. If there are concerns about abilities to alter templates or follow site building programs, consider hiring a pro for maximum ease. This will cost some serious money, but it can pay off with a well designed site.


  • Content creation.It doesn't matter whether a site is dedicated to chocolate or writing about current news events, content needs to go into place before the final launch. When using cheap web site design and hosting tools and templates, remember that keyword rich content that is relevant can drive traffic to a site. Some site owners write their own content, but others hire pros to do it for them. If the traffic and sales come, this investment is well worth the money. Do put some content in place prior to the launch, but plan on adding updates on a regular basis. This can keep a site looking and feeling fresh.


  • Launching. Once content is in place and the site is completely built, it's time to launch. Most cheap web site design and hosting offers make this very easy for clients to do. Just follow the instructions and the domain name used will very shortly have its own web site attached to it.

Author: This Article wrote by our team of experts and unique propery of Hosting-Review-Center (http://www.hosting-review-center.com).
Hosting-Review-Center ranks and review the best rated web hosting providers, windows and dedicated server hosting. Top 10 web hosting companies, small business web host, web host rating, web hosting articles and more.


This article is free for republishing
Source: http://www.a1articles.com/article_473352_2.html
Readmore »»

Fundamentals of ASP.Net programming vs. PHP programming


In this day’s websites normally requires simple web hosting plans for smooth performance of the website and email transfer that is essential. There are two modes of hosting planes are generally available, first is Linux hosting and second one is Windows hosting. Both have several advantages and disadvantages respectively but Depending upon small business owner’s requirements suitable managed hosting plan can be selected for a specific website.

Well in most of the normal situations, the general preference of small business owners for choosing web hosting plan moves towards the Linux server hosting plans rather than window server hosting, because there are numerous optimistic factor that influence people to choose it.

Expenditure Factor

The truth is that Linux hosting plans are much economical than Windows servers plans. For all small business people the web hosting price matters vastly. They wish to receive many options or you can say facilities at a tiny expenditure. Most of them not required supreme type of security and they also do not bother whether it is MS-SQL database server or some thing else to develop their database. Thus Linux server is the best option for them at really least cost with several kinds of features.

Open Source Factor

Linux is an Open Source code and enables people from all around the world to promote their own knowledge for its development. This is one of the main reasons where Linux servers have the power to eject Windows servers far away form competitive hosting industry. Now a day’s, due to its farthest adaptability Linux becomes a unique platform for lots of fresh technologies that are mostly used in competitive hosting industry. This means that a Linux server gives you numerous features than Windows servers can does.

Scripting Language Factor

There are many scripting language available on the Internet like Perl, Python, Java, and PHP to build your site. All these scripting languages and have been developed on Linux / UNIX web servers and they do not required Microsoft support to run them. But when you use those scripting languages which can be run on windows servers like ASP.Net then you require MS-SQL to develop the database and other supports of Microsoft. Now it is easily understandable that for small business owners Linux hosting is best to host their website into the internet.

Dependability Factor

Now a day’s Linux is vastly known as really steady and dependable. This means that Linux servers are little faster, easy to use and reputed as non crushable than a Windows server. Thus, Linux servers will provide more upgraded facilities for your website at a minimum outlay.

Familiarity and Executing Speed Factor

Linux servers have years of experience for providing services than Windows servers in hosting industry. There is no such recommendable difference in executing speed between Linux servers and Windows servers, but it is viewed that Linux servers are slightly quicker in processing normal website pages.

Efficiency Factor

Windows support ASP which is a programming language supported by Microsoft, which allows people to fabricate dynamic database motivated website pages by connecting with a MS-SQL server or Access server. It increase the production cost as well. Linux neither requires ASP language nor MS-SQL databases to build dynamic database driven website pages, because it simply uses MySQL database which is freely available.
This article is copyright
Source: http://www.a1articles.com/article_475534_2.html
Readmore »»

Learning Java Programming Language


There are many programming languages available and each of them is suitable for another program or application. There are people who have learnt only a few programming languages and who use these because that is what they know, bust most of the times software programmers will use the programming language that is required by the application they are creating. Java is one of the most frequently used programming language and writing in this language is somehow different from the usual Pascal or any C/C++ version but that does not mean that learning the java code is harder than learning Pascal or C++. Nowadays there are numerous applications written in Java and its terminology it may seem a bit harder in the beginning but anyone can write in this programming language, that's for sure.

When looking into a new programming language, most people would like to know if it is easy to learn and work in. If you compare it to C or C++, you may discover that indeed, using it can be more straight forward. This is due to the fact that Java has far fewer surprises compared to C versions. C and C++ make use of a lot of peculiarities so learning and mastering them all can be a daunting task (for example, temporary variables hang around long after the function that created them has terminated). Being more straight forward, Java is a bit easier to learn and to work with. Java eliminates explicit pointer dereferences and memory allocation/reclamation, for example, two of the most complicated sources of bugs for C and C++ programmers. Out of range subscripts are easy to find, as Java is able to do add array bounds checking. Others may argue that it seems easier to work with because there are very few examples of extremely complicated projects done using it, but the general accepted idea is that it is somehow easier to master than C or C++.

Learning Java programming is not very difficult, especially if you are familiar with other, more basic, programming languages and you know for sure what you want to create using it and it has a series of benefits compared to C and C++. First of all, code written in this programming language is portable. Code written in C and C++ is not and this makes Java more practical (for example, in C and C++, each implementation decides the precision and storage requirements for basic data types.

When you want to move from one system to another, this is a source of problems because changes in numeric precision can affect calculations). On the other hand, Java defines the size of basic types for all implementations (for example, an "int" on one system is the same size and it represents the same range of values as on every other given system). Find out more at http://www.whatiscomputerprogramming.com

The cases of programs that make use of floating point arithmetic requires a special attention: a program that uses floating point calculations can produce different answers on different systems (in this case, the degree of difference increases with the number of calculations a particular value goes through). But this is a thing specific to all floating point code, not only Java code which is also more portable then C or C++ in its object code. It compiles to an object code for a theoretical machine - in other words, the interpreter emulates that machine. This translates to the fact that code compiled on one computer will run on other computer machines that has a Java interpreter, but more on this subject you will find out while learning Java programming.


Learn more about computer programming languages including Computer Programming Training, tutorials and programming tools at => http://www.whatiscomputerprogramming.com
Readmore »»

09 February 2008

Free Hosting From 000webHost | PHP mySql free Hosting |

Free Web Hosting

Here comes the new free hosting from 000webhost.com its absolutely free host and no ads applied in the free host
the feature are
  1. 250 MB storage
  2. 100 GB transfer
  3. Php mysql support
  4. no advertising or banner embeded
  5. referal program for registered member
im already use its service and its very good for people who want a stabil freehost in the web
join now for free
click the banner for join
Free Web Hosting Readmore »»

06 February 2008

PHP Programing | PHP Basic | chapter 7 Classes and Object

class
A class is a collection of variables and functions working with these variables. A class is defined using the following syntax:
class Cart {
var $items; // Items in our shopping cart
// Add $num articles of $artnr to the cart
function add_item ($artnr, $num) {
$this->items[$artnr] += $num;
}
// Take $num articles of $artnr out of the cart
function remove_item ($artnr, $num) {
if ($this->items[$artnr] > $num) {
$this->items[$artnr] -= $num;
return true;
} else {
return false;
}
}
}
?>
This defines a class named Cart that consists of an associative array of articles in the cart and two functions to add and remove items from this cart.
Note: In PHP 4 and newer, only constant initializers for var variables are allowed. Use constructors for non-constant initializers.
/* None of these will work in PHP 4. */
class Cart {
var $todays_date = date("Y-m-d");
var $name = $firstname;
var $owner = 'Fred ' . 'Jones';
}

/* This is how it should be done. */
class Cart {
var $todays_date;
var $name;
var $owner;

function Cart() {
$this->todays_date = date("Y-m-d");
$this->name = $GLOBALS['firstname'];
/* etc. . . */
}
}
Classes are types, that is, they are blueprints for actual variables. You have to create a variable of the desired type with the new operator.
$cart = new Cart;
$cart->add_item("10", 1);
This creates an object $cart of the class Cart. The function add_item() of that object is being called to add 1 item of article number 10 to the cart.
Classes can be extensions of other classes. The extended or derived class has all variables and functions of the base class and what you add in the extended definition. This is done using the extends keyword. Multiple inheritance is not supported.
class Named_Cart extends Cart {
var $owner;
function set_owner ($name) {
$this->owner = $name;
}
}
This defines a class Named_Cart that has all variables and functions of Cart plus an additional variable $owner and an additional function set_owner(). You create a named cart the usual way and can now set and get the carts owner. You can still use normal cart functions on named carts:
$ncart = new Named_Cart; // Create a named cart
$ncart->set_owner ("kris"); // Name that cart
print $ncart->owner; // print the cart owners name
$ncart->add_item ("10", 1); // (inherited functionality from cart)
Within functions of a class the variable $this means this object. You have to use $this->something to access any variable or function named something within your current object. Both in and outside of the object you do not need a $ when accessing an object's properties.
$ncart->owner = "chris"; // no $

$ncart->$owner = "chris";
// this is invalid because $ncart->$owner = $ncart->""

$myvar = 'owner';
$ncart->$myvar = "chris";
// this is valid because $ncart->$myvar = $ncart->owner
Constructors are functions in a class that are automatically called when you create a new instance of a class. A function becomes a constructor when it has the same name as the class.
class Auto_Cart extends Cart {
function Auto_Cart () {
$this->add_item ("10", 1);
}
}
This defines a class Auto_Cart that is a Cart plus a constructor which initializes the cart with one item of article number "10" each time a new Auto_Cart is being made with "new". Constructors can also take arguments and these arguments can be optional, which makes them much more useful.
class Constructor_Cart extends Cart {
function Constructor_Cart ($item = "10", $num = 1) {
$this->add_item ($item, $num);
}
}
// Shop the same old boring stuff.
$default_cart = new Constructor_Cart;
// Shop for real...
$different_cart = new Constructor_Cart ("20", 17);
For derived classes, the constructor of the parent class is not automatically called when the derived class's constructor is called.
References inside the constructor
Creating references within the constructor can lead to confusing results. This tutorial-like section helps you to avoid problems.

class foo {
function foo($name) {
// create a reference inside the global array $globalref
global $globalref;
$globalref[] = &$this;
// set name to passed value
$this->setName($name);
// and put it out
$this->echoName();
}

function echoName() {
echo "
",$this->Name;
}
function setName($name) {
$this->Name = $name;
}
}
Let us check out if there is a difference between $bar1 which has been created using the copy = operator and $bar2 which has been created using the reference =& operator...
$bar1 = new foo('set in constructor');
$bar1->echoName();
$globalref[0]->echoName();
/* output:
set in constructor
set in constructor
set in constructor */
$bar2 =& new foo('set in constructor');
$bar2->echoName();
$globalref[1]->echoName();

/* output:
set in constructor
set in constructor
set in constructor */
Apparently there is no difference, but in fact there is a very significant one: $bar1 and $globalref[0] are _NOT_ referenced, they are NOT the same variable. This is because "new" does not return a reference by default, instead it returns a copy.
Note: There is no performance loss (since php 4 and up use reference counting) returning copies instead of references. On the contrary it is most often better to simply work with copies instead of references, because creating references takes some time where creating copies virtually takes no time (unless none of them is a large array or object and one of them gets changed and the other(s) one(s) subsequently, then it would be wise to use references to change them all concurrently).
To prove what is written above let us watch the code below.
// now we will change the name. what do you expect?
// you could expect that both $bar and $globalref[0] change their names...
$bar1->setName('set from outside');

// as mentioned before this is not the case.
$bar1->echoName();
$globalref[0]->echoName();

/* output:
set on object creation
set from outside */

// let us see what is different with $bar2 and $globalref[1]
$bar2->setName('set from outside');

// luckily they are not only equyl, they are thesame variable
// thus $bar2->Name and $globalref[1]->Name are the same too
$bar2->echoName();
$globalref[1]->echoName();

/* output:
set from outside
set from outside */
Another final example, try to understand it.

class a {
function a($i) {
$this->value = $i;
// try to figure out why we do not need a reference here
$this->b = new b($this);
}

function createRef() {
$this->c = new b($this);
}

function echoValue() {
echo "
","class ",get_class($this),': ',$this->value;
}
}


class b {

function b(&$a) {
$this->a = &$a;
}

function echoValue() {
echo "
","class ",get_class($this),': ',$this->a->value;
}

}

// try to undestand why using a simple copy here would yield
// in an undesired result in the *-marked line
$a =& new a(10);
$a->createRef();

$a->echoValue();
$a->b->echoValue();
$a->c->echoValue();

$a->value = 11;

$a->echoValue();
$a->b->echoValue(); // *
$a->c->echoValue();

/*
output:
class a: 10
class b: 10
class b: 10
class a: 11
class b: 11
class b: 11
*/

Article 8
Title : PHP Programing | PHP Basic | chapter 8 References
References are a means in PHP to access the same variable content by different names. They are not like C pointers, they are symbol table aliases. Note that in PHP, variable name and variable content are different, so the same content can have different names. The most close analogy is with Unix filenames and files - variable names are directory entries, while variable contents is the file itself. References can be thought of as hardlinking in Unix filesystem.
PHP references allow you to make two variables to refer to the same content. Meaning, when you do:
$a =& $b
it means that $a and $b point to the same variable.
Note: $a and $b are completely equal here, that's not $a is pointing to $b or vice versa, that's $a and $b pointing to the same place.
The same syntax can be used with functions, that return references, and with new operator (in PHP 4.0.4 and later):
$bar =& new fooclass();
$foo =& find_var ($bar);
Note: Unless you use the syntax above, the result of $bar = new fooclass() will not be the same variable as $this in the constructor, meaning that if you have used reference to $this in the constructor, you should use reference assignment, or you get two different objects.
The second thing references do is to pass variables by-reference. This is done by making a local variable in a function and a variable in the calling scope reference to the same content. Example:
function foo (&$var) {
$var++;
}

$a=5;
foo ($a);
will make $a to be 6. This happens because in the function foo the variable $var refers to the same content as $a
Passing by Reference
You can pass variable to function by reference, so that function could modify its arguments. The sytax is as follows:
function foo (&$var) {
$var++;
}

$a=5;
foo ($a);
// $a is 6 here
Note that there's no reference sign on function call - only on function definition. Function definition alone is enough to correctly pass the argument by reference.
Following things can be passed by reference:
· Variable, i.e. foo($a)
· New statement, i.e. foo(new foobar())
· Reference, returned from a function, i.e.:
function &bar()
{
$a = 5;
return $a;
}
foo(bar());
Any other expression should not be passed by reference, as the result is undefined. For example, the following examples of passing by reference are invalid:
function bar() // Note the missing &
{
$a = 5;
return $a;
}
foo(bar));

foo($a = 5) // Expression, not variable
foo(5) // Constant, not variable
These requirements are for PHP 4.0.4 and later.
Returning References
Returning by-reference is useful when you want to use a function to find which variable a reference should be bound to. When returning references, use this syntax:
function &find_var ($param) {
...code...
return $found_var;
}

$foo =& find_var ($bar);
$foo->x = 2;
In this example, the property of the object returned by the find_var function would be set, not the copy, as it would be without using reference syntax.
Note: Unlike parameter passing, here you have to use & in both places - to indicate that you return by-reference, not a copy as usual, and to indicate that reference binding, rather than usual assignment, should be done for $foo.
Unsetting References
When you unset the reference, you just break the binding between variable name and variable content. This does not mean that variable content will be destroyed. For example:
$a = 1;
$b =& $a;
unset ($a);
won't unset $b, just $a.
Again, it might be useful to think about this as analogous to Unix unlink call.
Spotting References
Many syntax constructs in PHP are implemented via referencing mechanisms, so everything told above about reference binding also apply to these constructs. Some constructs, like passing and returning by-reference, are mentioned above. Other constructs that use references are:
global References
When you declare variable as global $var you are in fact creating reference to a global variable. That means, this is the same as:
$var =& $GLOBALS["var"];
That means, for example, that unsetting $var won't unset global variable.
$this
In an object method, $this is always reference to the caller object.
This is the last chapter I write about PHP but it doesn’t mean that PHP only until this subject because there much more about PHP.and in my article is very litle part from the Big Part of PHP. Next time I will discused about PHP again with more advanced chapter about PHP. Thanks to all my friend for the help writing this article. Readmore »»

PHP Programing | PHP Basic | chapter 5 Control Structure

Any PHP script is built out of a series of statements. A statement can be an assignment, a function call, a loop, a conditional statement of even a statement that does nothing (an empty statement). Statements usually end with a semicolon. In addition, statements can be grouped into a statement-group by encapsulating a group of statements with curly braces. A statement-group is a statement by itself as well. The various statement types are described in this chapter
if
The if construct is one of the most important features of many languages, PHP included. It allows for conditional execution of code fragments. PHP features an if structure that is similar to that of C:
if (expr)
statement
As described in the section about expressions, expr is evaluated to its truth value. If expr evaluates to TRUE, PHP will execute statement, and if it evaluates to FALSE - it'll ignore it.
The following example would display a is bigger than b if $a is bigger than $b:
if ($a > $b)
print "a is bigger than b";
Often you'd want to have more than one statement to be executed conditionally. Of course, there's no need to wrap each statement with an if clause. Instead, you can group several statements into a statement group. For example, this code would display a is bigger than b if $a is bigger than $b, and would then assign the value of $a into $b:
if ($a > $b) {
print "a is bigger than b";
$b = $a;
}
If statements can be nested indefinitely within other if statements, which provides you with complete flexibility for conditional execution of the various parts of your program.
else
Often you'd want to execute a statement if a certain condition is met, and a different statement if the condition is not met. This is what else is for. else extends an if statement to execute a statement in case the expression in the if statement evaluates to FALSE. For example, the following code would display a is bigger than b if $a is bigger than $b, and a is NOT bigger than b otherwise:
if ($a > $b) {
print "a is bigger than b";
} else {
print "a is NOT bigger than b";
}
The else statement is only executed if the if expression evaluated to FALSE, and if there were any elseif expressions - only if they evaluated to FALSE as well.
elseif
elseif, as its name suggests, is a combination of if and else. Like else, it extends an if statement to execute a different statement in case the original if expression evaluates to FALSE. However, unlike else, it will execute that alternative expression only if the elseif conditional expression evaluates to TRUE. For example, the following code would display a is bigger than b, a equal to b or a is smaller than b:
if ($a > $b) {
print "a is bigger than b";
} elseif ($a == $b) {
print "a is equal to b";
} else {
print "a is smaller than b";
}
There may be several elseifs within the same if statement. The first elseif expression (if any) that evaluates to true would be executed. In PHP, you can also write 'else if' (in two words) and the behavior would be identical to the one of 'elseif' (in a single word). The syntactic meaning is slightly different (if you're familiar with C, this is the same behavior) but the bottom line is that both would result in exactly the same behavior.
The elseif statement is only executed if the preceding if expression and any preceding elseif expressions evaluated to FALSE, and the current elseif expression evaluated to TRUE.
Alternative syntax for control structures
PHP offers an alternative syntax for some of its control structures; namely, if, while, for, foreach, and switch. In each case, the basic form of the alternate syntax is to change the opening brace to a colon (:) and the closing brace to endif;, endwhile;, endfor;, endforeach;, or endswitch;, respectively.

A is equal to 5

In the above example, the HTML block "A = 5" is nested within an if statement written in the alternative syntax. The HTML block would be displayed only if $a is equal to 5.
The alternative syntax applies to else and elseif as well. The following is an if structure with elseif and else in the alternative format:
if ($a == 5):
print "a equals 5";
print "...";
elseif ($a == 6):
print "a equals 6";
print "!!!";
else:
print "a is neither 5 nor 6";
endif;

while
while loops are the simplest type of loop in PHP. They behave just like their C counterparts. The basic form of a while statement is:
while (expr) statement
The meaning of a while statement is simple. It tells PHP to execute the nested statement(s) repeatedly, as long as the while expression evaluates to TRUE. The value of the expression is checked each time at the beginning of the loop, so even if this value changes during the execution of the nested statement(s), execution will not stop until the end of the iteration (each time PHP runs the statements in the loop is one iteration). Sometimes, if the while expression evaluates to FALSE from the very beginning, the nested statement(s) won't even be run once.
Like with the if statement, you can group multiple statements within the same while loop by surrounding a group of statements with curly braces, or by using the alternate syntax:
while (expr): statement ... endwhile;
The following examples are identical, and both print numbers from 1 to 10:
/* example 1 */

$i = 1;
while ($i <= 10) {
print $i++; /* the printed value would be
$i before the increment
(post-increment) */
}
/* example 2 */
$i = 1;
while ($i <= 10):
print $i;
$i++;
endwhile;
do..while
do..while loops are very similar to while loops, except the truth expression is checked at the end of each iteration instead of in the beginning. The main difference from regular while loops is that the first iteration of a do..while loop is guarenteed to run (the truth expression is only checked at the end of the iteration), whereas it's may not necessarily run with a regular while loop (the truth expression is checked at the beginning of each iteration, if it evaluates to FALSE right from the beginning, the loop execution would end immediately).
There is just one syntax for do..while loops:
$i = 0;
do {
print $i;
} while ($i>0);
The above loop would run one time exactly, since after the first iteration, when truth expression is checked, it evaluates to FALSE ($i is not bigger than 0) and the loop execution ends.
Advanced C users may be familiar with a different usage of the do..while loop, to allow stopping execution in the middle of code blocks, by encapsulating them with do..while(0), and using the break statement. The following code fragment demonstrates this:
do {
if ($i < 5) {
print "i is not big enough";
break;
}
$i *= $factor;
if ($i < $minimum_limit) {
break;
}
print "i is ok";

...process i...

} while(0);
Don't worry if you don't understand this right away or at all. You can code scripts and even powerful scripts without using this `feature'.
for
for loops are the most complex loops in PHP. They behave like their C counterparts. The syntax of a for loop is:
for (expr1; expr2; expr3) statement
The first expression (expr1) is evaluated (executed) once unconditionally at the beginning of the loop.
In the beginning of each iteration, expr2 is evaluated. If it evaluates to TRUE, the loop continues and the nested statement(s) are executed. If it evaluates to FALSE, the execution of the loop ends.
At the end of each iteration, expr3 is evaluated (executed).
Each of the expressions can be empty. expr2 being empty means the loop should be run indefinitely (PHP implicitly considers it as TRUE, like C). This may not be as useless as you might think, since often you'd want to end the loop using a conditional break statement instead of using the for truth expression.
Consider the following examples. All of them display numbers from 1 to 10:
/* example 1 */
for ($i = 1; $i <= 10; $i++) {
print $i;
}
/* example 2 */
for ($i = 1;;$i++) {
if ($i > 10) {
break;
}
print $i;
}
/* example 3 */
$i = 1;
for (;;) {
if ($i > 10) {
break;
}
print $i;
$i++;
}
/* example 4 */
for ($i = 1; $i <= 10; print $i, $i++) ;
Of course, the first example appears to be the nicest one (or perhaps the fourth), but you may find that being able to use empty expressions in for loops comes in handy in many occasions.
PHP also supports the alternate "colon syntax" for for loops.
for (expr1; expr2; expr3): statement; ...; endfor;
Other languages have a foreach statement to traverse an array or hash. PHP 3 has no such construct; PHP 4 does (see foreach). In PHP 3, you can combine while with the list() and each() functions to achieve the same effect.
foreach
PHP 4 includes a foreach construct, much like perl and some other languages. This simply gives an easy way to iterate over arrays. There are two syntaxes; the second is a minor but useful extension of the first:
foreach(array_expression as $value) statement
foreach(array_expression as $key => $value) statement
The first form loops over the array given by array_expression. On each loop, the value of the current element is assigned to $value and the internal array pointer is advanced by one (so on the next loop, you'll be looking at the next element).
The second form does the same thing, except that the current element's key will be assigned to the variable $key on each loop.
Note: When foreach first starts executing, the internal array pointer is automatically reset to the first element of the array. This means that you do not need to call reset() before a foreach loop.
Note: Also note that foreach operates on a copy of the specified array, not the array itself, therefore the array pointer is not modified like with the each construct.
You may have noticed that the following are functionally identical:
reset ($arr);
while (list(, $value) = each ($arr)) {
echo "Value: $value
\n";
}

foreach ($arr as $value) {
echo "Value: $value
\n";
}
The following are also functionally identical:
reset ($arr);
while (list($key, $value) = each ($arr)) {
echo "Key: $key; Value: $value
\n";
}

foreach ($arr as $key => $value) {
echo "Key: $key; Value: $value
\n";
}
Some more examples to demonstrate usages:
/* foreach example 1: value only */

$a = array (1, 2, 3, 17);

foreach ($a as $v) {
print "Current value of \$a: $v.\n";
}

/* foreach example 2: value (with key printed for illustration) */

$a = array (1, 2, 3, 17);

$i = 0; /* for illustrative purposes only */

foreach($a as $v) {
print "\$a[$i] => $v.\n";
}

/* foreach example 3: key and value */

$a = array (
"one" => 1,
"two" => 2,
"three" => 3,
"seventeen" => 17
);

foreach($a as $k => $v) {
print "\$a[$k] => $v.\n";
}
break
break ends execution of the current for, while, or switch structure. break accepts an optional numeric argument which tells it how many nested enclosing structures are to be broken out of.
$arr = array ('one', 'two', 'three', 'four', 'stop', 'five');
while (list (, $val) = each ($arr)) {
if ($val == 'stop') {
break; /* You could also write 'break 1;' here. */
}
echo "$val
\n";
}

/* Using the optional argument. */

$i = 0;
while (++$i) {
switch ($i) {
case 5:
echo "At 5
\n";
break 1; /* Exit only the switch. */
case 10:
echo "At 10; quitting
\n";
break 2; /* Exit the switch and the while. */
default:
break;
}
}
continue
continue is used within looping structures to skip the rest of the current loop iteration and continue execution at the beginning of the next iteration. continue accepts an optional numeric argument which tells it how many levels of enclosing loops it should skip to the end of.
while (list ($key, $value) = each ($arr)) {
if (!($key % 2)) { // skip odd members
continue;
}
do_something_odd ($value);
}

$i = 0;
while ($i++ < 5) {
echo "Outer
\n";
while (1) {
echo "  Middle
\n";
while (1) {
echo "  Inner
\n";
continue 3;
}
echo "This never gets output.
\n";
}
echo "Neither does this.
\n";
}
switch
The switch statement is similar to a series of IF statements on the same expression. In many occasions, you may want to compare the same variable (or expression) with many different values, and execute a different piece of code depending on which value it equals to. This is exactly what the switch statement is for.
The following two examples are two different ways to write the same thing, one using a series of if statements, and the other using the switch statement:
if ($i == 0) {
print "i equals 0";
}
if ($i == 1) {
print "i equals 1";
}
if ($i == 2) {
print "i equals 2";
}
switch ($i) {
case 0:
print "i equals 0";
break;
case 1:
print "i equals 1";
break;
case 2:
print "i equals 2";
break;
}
It is important to understand how the switch statement is executed in order to avoid mistakes. The switch statement executes line by line (actually, statement by statement). In the beginning, no code is executed. Only when a case statement is found with a value that matches the value of the switch expression does PHP begin to execute the statements. PHP continues to execute the statements until the end of the switch block, or the first time it sees a break statement. If you don't write a break statement at the end of a case's statement list, PHP will go on executing the statements of the following case. For example:
switch ($i) {
case 0:
print "i equals 0";
case 1:
print "i equals 1";
case 2:
print "i equals 2";
}
Here, if $i equals to 0, PHP would execute all of the print statements! If $i equals to 1, PHP would execute the last two print statements, and only if $i equals to 2, you'd get the 'expected' behavior and only 'i equals 2' would be displayed. So, it's important not to forget break statements (even though you may want to avoid supplying them on purpose under certain circumstances).
In a switch statement, the condition is evaluated only once and the result is compared to each case statement. In an elseif statement, the condition is evaluated again. If your condition is more complicated than a simple compare and/or is in a tight loop, a switch may be faster.
The statement list for a case can also be empty, which simply passes control into the statement list for the next case.
switch ($i) {
case 0:
case 1:
case 2:
print "i is less than 3 but not negative";
break;
case 3:
print "i is 3";
}
A special case is the default case. This case matches anything that wasn't matched by the other cases, and should be the last case statement. For example:
switch ($i) {
case 0:
print "i equals 0";
break;
case 1:
print "i equals 1";
break;
case 2:
print "i equals 2";
break;
default:
print "i is not equal to 0, 1 or 2";
}
The case expression may be any expression that evaluates to a simple type, that is, integer or floating-point numbers and strings. Arrays or objects cannot be used here unless they are dereferenced to a simple type.
The alternative syntax for control structures is supported with switches.
switch ($i):
case 0:
print "i equals 0";
break;
case 1:
print "i equals 1";
break;
case 2:
print "i equals 2";
break;
default:
print "i is not equal to 0, 1 or 2";
endswitch;
require()
The require() statement replaces itself with the specified file, much like the C preprocessor's #include works.
If "URL fopen wrappers" are enabled in PHP (which they are in the default configuration), you can specify the file to be require()ed using an URL instead of a local pathname. See Remote files and fopen() for more information.
An important note about how this works is that when a file is include()ed or require()ed, parsing drops out of PHP mode and into HTML mode at the beginning of the target file, and resumes PHP mode again at the end. For this reason, any code inside the target file which should be executed as PHP code must be enclosed within valid PHP start and end tags.
require() is not actually a function in PHP; rather, it is a language construct. It is subject to some different rules than functions are. For instance, require() is not subject to any containing control structures. For another, it does not return any value; attempting to read a return value from a require() call results in a parse error.
Unlike include(), require() will always read in the target file, even if the line it's on never executes. If you want to conditionally include a file, use include(). The conditional statement won't affect the require(). However, if the line on which the require() occurs is not executed, neither will any of the code in the target file be executed.
Similarly, looping structures do not affect the behaviour of require(). Although the code contained in the target file is still subject to the loop, the require() itself happens only once.
This means that you can't put a require() statement inside of a loop structure and expect it to include the contents of a different file on each iteration. To do that, use an include() statement.
require ('header.inc');
When a file is require()ed, the code it contains inherits the variable scope of the line on which the require() occurs. Any variables available at that line in the calling file will be available within the called file. If the require() occurs inside a function within the calling file, then all of the code contained in the called file will behave as though it had been defined inside that function.
If the require()ed file is called via HTTP using the fopen wrappers, and if the target server interprets the target file as PHP code, variables may be passed to the require()ed file using an URL request string as used with HTTP GET. This is not strictly speaking the same thing as require()ing the file and having it inherit the parent file's variable scope; the script is actually being run on the remote server and the result is then being included into the local script.
/* This example assumes that someserver is configured to parse .php
* files and not .txt files. Also, 'works' here means that the variables
* $varone and $vartwo are available within the require()ed file. */

/* Won't work; file.txt wasn't handled by someserver. */
require ("http://someserver/file.txt?varone=1&vartwo=2");

/* Won't work; looks for a file named 'file.php?varone=1&vartwo=2'
* on the local filesystem. */
require ("file.php?varone=1&vartwo=2");

/* Works. */
require ("http://someserver/file.php?varone=1&vartwo=2");

$varone = 1;
$vartwo = 2;
require ("file.txt"); /* Works. */
require ("file.php"); /* Works. */
In PHP 3, it is possible to execute a return statement inside a require()ed file, as long as that statement occurs in the global scope of the require()ed file. It may not occur within any block (meaning inside braces ({}). In PHP 4, however, this ability has been discontinued.
include()
The include() statement includes and evaluates the specified file.
If "URL fopen wrappers" are enabled in PHP (which they are in the default configuration), you can specify the file to be include()ed using an URL instead of a local pathname. See Remote files and fopen() for more information.
An important note about how this works is that when a file is include()ed or require()ed, parsing drops out of PHP mode and into HTML mode at the beginning of the target file, and resumes again at the end. For this reason, any code inside the target file which should be executed as PHP code must be enclosed within valid PHP start and end tags.
This happens each time the include() statement is encountered, so you can use an include() statement within a looping structure to include a number of different files.
$files = array ('first.inc', 'second.inc', 'third.inc');
for ($i = 0; $i < count($files); $i++) {
include $files[$i];
}
include() differs from require() in that the include statement is re-evaluated each time it is encountered (and only when it is being executed), whereas the require() statement is replaced by the required file when it is first encountered, whether the contents of the file will be evaluated or not (for example, if it is inside an if statement whose condition evaluated to false).
Because include() is a special language construct, you must enclose it within a statement block if it is inside a conditional block.
/* This is WRONG and will not work as desired. */
if ($condition)
include($file);
else
include($other);
/* This is CORRECT. */
if ($condition) {
include($file);
} else {
include($other);
}
In both PHP 3 and PHP 4, it is possible to execute a return statement inside an include()ed file, in order to terminate processing in that file and return to the script which called it. Some differences in the way this works exist, however. The first is that in PHP 3, the return may not appear inside a block unless it's a function block, in which case the return applies to that function and not the whole file. In PHP 4, however, this restriction does not exist. Also, PHP 4 allows you to return values from include()ed files. You can take the value of the include() call as you would a normal function. This generates a parse error in PHP 3.
When a file is include()ed, the code it contains inherits the variable scope of the line on which the include() occurs. Any variables available at that line in the calling file will be available within the called file. If the include() occurs inside a function within the calling file, then all of the code contained in the called file will behave as though it had been defined inside that function.
If the include()ed file is called via HTTP using the fopen wrappers, and if the target server interprets the target file as PHP code, variables may be passed to the include()ed file using an URL request string as used with HTTP GET. This is not strictly speaking the same thing as include()ing the file and having it inherit the parent file's variable scope; the script is actually being run on the remote server and the result is then being included into the local script.
/* This example assumes that someserver is configured to parse .php
* files and not .txt files. Also, 'works' here means that the variables
* $varone and $vartwo are available within the include()ed file. */

/* Won't work; file.txt wasn't handled by someserver. */
include ("http://someserver/file.txt?varone=1&vartwo=2");

/* Won't work; looks for a file named 'file.php?varone=1&vartwo=2'
* on the local filesystem. */
include ("file.php?varone=1&vartwo=2");

/* Works. */
include ("http://someserver/file.php?varone=1&vartwo=2");

$varone = 1;
$vartwo = 2;
include ("file.txt"); /* Works. */
include ("file.php"); /* Works. */
require_once()
The require_once() statement replaces itself with the specified file, much like the C preprocessor's #include works, and in that respect is similar to the require() statement. The main difference is that in an inclusion chain, the use of require_once() will assure that the code is added to your script only once, and avoid clashes with variable values or function names that can happen.
For example, if you create the following 2 include files utils.inc and foolib.inc
utils.inc
define(PHPVERSION, floor(phpversion()));
echo "GLOBALS ARE NICE\n";
function goodTea() {
return "Oolong tea tastes good!";
}
?>

foolib.inc
require ("utils.inc");
function showVar($var) {
if (PHPVERSION == 4) {
print_r($var);
} else {
var_dump($var);
}
}

// bunch of other functions ...
?>

And then you write a script cause_error_require.php
cause_error_require.php
require("foolib.inc");
/* the following will generate an error */
require("utils.inc");
$foo = array("1",array("complex","quaternion"));
echo "this is requiring utils.inc again which is also\n";
echo "required in foolib.inc\n";
echo "Running goodTea: ".goodTea()."\n";
echo "Printing foo: \n";
showVar($foo);
?>

When you try running the latter one, the resulting ouptut will be (using PHP 4.01pl2):
GLOBALS ARE NICE
GLOBALS ARE NICE

Fatal error: Cannot redeclare goodTea() in utils.inc on line 5
By modifying foolib.inc and cause_errror_require.php to use require_once() instead of require() and renaming the last one to avoid_error_require_once.php, we have:
foolib.inc (fixed)
...
require_once("utils.inc");
function showVar($var) {
...

avoid_error_require_once.php
...
require_once("foolib.inc");
require_once("utils.inc");
$foo = array("1",array("complex","quaternion"));
...

And when running the latter, the output will be (using PHP 4.0.1pl2):
GLOBALS ARE NICE
this is requiring globals.inc again which is also
required in foolib.inc
Running goodTea: Oolong tea tastes good!
Printing foo:
Array
(
[0] => 1
[1] => Array
(
[0] => complex
[1] => quaternion
)

)
Also note that, analogous to the behavior of the #include of the C preprocessor, this statement acts at "compile time", e.g. when the script is parsed and before it is executed, and should not be used for parts of the script that need to be inserted dynamically during its execution. You should use include_once() or include() for that purpose.
For more examples on using require_once() and include_once(), look at the PEAR code included in the latest PHP source code distributions.
include_once()
The include_once() statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the include() statement, with the important difference that if the code from a file has already been included, it will not be included again.
As mentioned in the require_once() description, the include_once() should be used in the cases in which the same file might be included and evaluated more than once during a particular execution of a script, and you want to be sure that it is included exactly once to avoid problems with function redefinitions, variable value reassignments, etc.
Finaly our arrengement about control structure finished. Are you confused about what im talking about? I know when there is a will there is a way. With study hard Im sure you can understand and apply the knowledge in your life. In the next chapter I will easied up a subject about function inluding the user defined function, function arguments etc.
Chapter 6
Title : PHP Programing | PHP Basic | chapter 6 Functions
User-defined functions
A function may be defined using syntax such as the following:
function foo ($arg_1, $arg_2, ..., $arg_n) {
echo "Example function.\n";
return $retval;
}
Any valid PHP code may appear inside a function, even other functions and class definitions.
In PHP 3, functions must be defined before they are referenced. No such requirement exists in PHP 4.
PHP does not support function overloading, nor is it possible to undefine or redefine previously-declared functions.
PHP 3 does not support variable numbers of arguments to functions, although default arguments are supported (see Default argument values for more information). PHP 4 supports both: see Variable-length argument lists and the function references for func_num_args(), func_get_arg(), and func_get_args() for more information.
Function arguments
Information may be passed to functions via the argument list, which is a comma-delimited list of variables and/or constants.
PHP supports passing arguments by value (the default), passing by reference, and default argument values. Variable-length argument lists are supported only in PHP 4 and later; see Variable-length argument lists and the function references for func_num_args(), func_get_arg(), and func_get_args() for more information. A similar effect can be achieved in PHP 3 by passing an array of arguments to a function:
function takes_array($input) {
echo "$input[0] + $input[1] = ", $input[0]+$input[1];
}
Making arguments be passed by reference
By default, function arguments are passed by value (so that if you change the value of the argument within the function, it does not get changed outside of the function). If you wish to allow a function to modify its arguments, you must pass them by reference.
If you want an argument to a function to always be passed by reference, you can prepend an ampersand (&) to the argument name in the function definition:
function add_some_extra(&$string) {
$string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str; // outputs 'This is a string, and something extra.'
If you wish to pass a variable by reference to a function which does not do this by default, you may prepend an ampersand to the argument name in the function call:
function foo ($bar) {
$bar .= ' and something extra.';
}
$str = 'This is a string, ';
foo ($str);
echo $str; // outputs 'This is a string, '
foo (&$str);
echo $str; // outputs 'This is a string, and something extra.'
Default argument values
A function may define C++-style default values for scalar arguments as follows:
function makecoffee ($type = "cappucino") {
return "Making a cup of $type.\n";
}
echo makecoffee ();
echo makecoffee ("espresso");
The output from the above snippet is:
Making a cup of cappucino.
Making a cup of espresso.
The default value must be a constant expression, not (for example) a variable or class member.
Note that when using default arguments, any defaults should be on the right side of any non-default arguments; otherwise, things will not work as expected. Consider the following code snippet:
function makeyogurt ($type = "acidophilus", $flavour) {
return "Making a bowl of $type $flavour.\n";
}
echo makeyogurt ("raspberry"); // won't work as expected
The output of the above example is:
Warning: Missing argument 2 in call to makeyogurt() in
/usr/local/etc/httpd/htdocs/php3test/functest.html on line 41
Making a bowl of raspberry .
Now, compare the above with this:
function makeyogurt ($flavour, $type = "acidophilus") {
return "Making a bowl of $type $flavour.\n";
}
echo makeyogurt ("raspberry"); // works as expected
The output of this example is:
Making a bowl of acidophilus raspberry.
Variable-length argument lists
PHP 4 has support for variable-length argument lists in user-defined functions. This is really quite easy, using the func_num_args(), func_get_arg(), and func_get_args() functions.
No special syntax is required, and argument lists may still be explicitly provided with function definitions and will behave as normal.
Returning values
Values are returned by using the optional return statement. Any type may be returned, including lists and objects.
function square ($num) {
return $num * $num;
}
echo square (4); // outputs '16'.
You can't return multiple values from a function, but similar results can be obtained by returning a list.
function small_numbers() {
return array (0, 1, 2);
}
list ($zero, $one, $two) = small_numbers();
To return a reference from a function, you have to use the reference operator & in both the function declaration and when assigning the returned value to a variable:
function &returns_reference() {
return $someref;
}

$newref =&returns_reference();
Variable functions
PHP supports the concept of variable functions. This means that if a variable name has parentheses appended to it, PHP will look for a function with the same name as whatever the variable evaluates to, and will attempt to execute it. Among other things, this can be used to implement callbacks, function tables, and so forth.
Variable function example
function foo() {
echo "In foo()
\n";
}

function bar( $arg = '' ) {
echo "In bar(); argument was '$arg'.
\n";
}

$func = 'foo';
$func();
$func = 'bar';
$func( 'test' );
?> Readmore »»

PHP Programing | PHP Basic | chapter 5 Control Structure

Any PHP script is built out of a series of statements. A statement can be an assignment, a function call, a loop, a conditional statement of even a statement that does nothing (an empty statement). Statements usually end with a semicolon. In addition, statements can be grouped into a statement-group by encapsulating a group of statements with curly braces. A statement-group is a statement by itself as well. The various statement types are described in this chapter
if
The if construct is one of the most important features of many languages, PHP included. It allows for conditional execution of code fragments. PHP features an if structure that is similar to that of C:
if (expr)
statement
As described in the section about expressions, expr is evaluated to its truth value. If expr evaluates to TRUE, PHP will execute statement, and if it evaluates to FALSE - it'll ignore it.
The following example would display a is bigger than b if $a is bigger than $b:
if ($a > $b)
print "a is bigger than b";
Often you'd want to have more than one statement to be executed conditionally. Of course, there's no need to wrap each statement with an if clause. Instead, you can group several statements into a statement group. For example, this code would display a is bigger than b if $a is bigger than $b, and would then assign the value of $a into $b:
if ($a > $b) {
print "a is bigger than b";
$b = $a;
}
If statements can be nested indefinitely within other if statements, which provides you with complete flexibility for conditional execution of the various parts of your program.
else
Often you'd want to execute a statement if a certain condition is met, and a different statement if the condition is not met. This is what else is for. else extends an if statement to execute a statement in case the expression in the if statement evaluates to FALSE. For example, the following code would display a is bigger than b if $a is bigger than $b, and a is NOT bigger than b otherwise:
if ($a > $b) {
print "a is bigger than b";
} else {
print "a is NOT bigger than b";
}
The else statement is only executed if the if expression evaluated to FALSE, and if there were any elseif expressions - only if they evaluated to FALSE as well.
elseif
elseif, as its name suggests, is a combination of if and else. Like else, it extends an if statement to execute a different statement in case the original if expression evaluates to FALSE. However, unlike else, it will execute that alternative expression only if the elseif conditional expression evaluates to TRUE. For example, the following code would display a is bigger than b, a equal to b or a is smaller than b:
if ($a > $b) {
print "a is bigger than b";
} elseif ($a == $b) {
print "a is equal to b";
} else {
print "a is smaller than b";
}
There may be several elseifs within the same if statement. The first elseif expression (if any) that evaluates to true would be executed. In PHP, you can also write 'else if' (in two words) and the behavior would be identical to the one of 'elseif' (in a single word). The syntactic meaning is slightly different (if you're familiar with C, this is the same behavior) but the bottom line is that both would result in exactly the same behavior.
The elseif statement is only executed if the preceding if expression and any preceding elseif expressions evaluated to FALSE, and the current elseif expression evaluated to TRUE.
Alternative syntax for control structures
PHP offers an alternative syntax for some of its control structures; namely, if, while, for, foreach, and switch. In each case, the basic form of the alternate syntax is to change the opening brace to a colon (:) and the closing brace to endif;, endwhile;, endfor;, endforeach;, or endswitch;, respectively.

A is equal to 5

In the above example, the HTML block "A = 5" is nested within an if statement written in the alternative syntax. The HTML block would be displayed only if $a is equal to 5.
The alternative syntax applies to else and elseif as well. The following is an if structure with elseif and else in the alternative format:
if ($a == 5):
print "a equals 5";
print "...";
elseif ($a == 6):
print "a equals 6";
print "!!!";
else:
print "a is neither 5 nor 6";
endif;

while
while loops are the simplest type of loop in PHP. They behave just like their C counterparts. The basic form of a while statement is:
while (expr) statement
The meaning of a while statement is simple. It tells PHP to execute the nested statement(s) repeatedly, as long as the while expression evaluates to TRUE. The value of the expression is checked each time at the beginning of the loop, so even if this value changes during the execution of the nested statement(s), execution will not stop until the end of the iteration (each time PHP runs the statements in the loop is one iteration). Sometimes, if the while expression evaluates to FALSE from the very beginning, the nested statement(s) won't even be run once.
Like with the if statement, you can group multiple statements within the same while loop by surrounding a group of statements with curly braces, or by using the alternate syntax:
while (expr): statement ... endwhile;
The following examples are identical, and both print numbers from 1 to 10:
/* example 1 */

$i = 1;
while ($i <= 10) {
print $i++; /* the printed value would be
$i before the increment
(post-increment) */
}
/* example 2 */
$i = 1;
while ($i <= 10):
print $i;
$i++;
endwhile;
do..while
do..while loops are very similar to while loops, except the truth expression is checked at the end of each iteration instead of in the beginning. The main difference from regular while loops is that the first iteration of a do..while loop is guarenteed to run (the truth expression is only checked at the end of the iteration), whereas it's may not necessarily run with a regular while loop (the truth expression is checked at the beginning of each iteration, if it evaluates to FALSE right from the beginning, the loop execution would end immediately).
There is just one syntax for do..while loops:
$i = 0;
do {
print $i;
} while ($i>0);
The above loop would run one time exactly, since after the first iteration, when truth expression is checked, it evaluates to FALSE ($i is not bigger than 0) and the loop execution ends.
Advanced C users may be familiar with a different usage of the do..while loop, to allow stopping execution in the middle of code blocks, by encapsulating them with do..while(0), and using the break statement. The following code fragment demonstrates this:
do {
if ($i < 5) {
print "i is not big enough";
break;
}
$i *= $factor;
if ($i < $minimum_limit) {
break;
}
print "i is ok";

...process i...

} while(0);
Don't worry if you don't understand this right away or at all. You can code scripts and even powerful scripts without using this `feature'.
for
for loops are the most complex loops in PHP. They behave like their C counterparts. The syntax of a for loop is:
for (expr1; expr2; expr3) statement
The first expression (expr1) is evaluated (executed) once unconditionally at the beginning of the loop.
In the beginning of each iteration, expr2 is evaluated. If it evaluates to TRUE, the loop continues and the nested statement(s) are executed. If it evaluates to FALSE, the execution of the loop ends.
At the end of each iteration, expr3 is evaluated (executed).
Each of the expressions can be empty. expr2 being empty means the loop should be run indefinitely (PHP implicitly considers it as TRUE, like C). This may not be as useless as you might think, since often you'd want to end the loop using a conditional break statement instead of using the for truth expression.
Consider the following examples. All of them display numbers from 1 to 10:
/* example 1 */
for ($i = 1; $i <= 10; $i++) {
print $i;
}
/* example 2 */
for ($i = 1;;$i++) {
if ($i > 10) {
break;
}
print $i;
}
/* example 3 */
$i = 1;
for (;;) {
if ($i > 10) {
break;
}
print $i;
$i++;
}
/* example 4 */
for ($i = 1; $i <= 10; print $i, $i++) ;
Of course, the first example appears to be the nicest one (or perhaps the fourth), but you may find that being able to use empty expressions in for loops comes in handy in many occasions.
PHP also supports the alternate "colon syntax" for for loops.
for (expr1; expr2; expr3): statement; ...; endfor;
Other languages have a foreach statement to traverse an array or hash. PHP 3 has no such construct; PHP 4 does (see foreach). In PHP 3, you can combine while with the list() and each() functions to achieve the same effect.
foreach
PHP 4 includes a foreach construct, much like perl and some other languages. This simply gives an easy way to iterate over arrays. There are two syntaxes; the second is a minor but useful extension of the first:
foreach(array_expression as $value) statement
foreach(array_expression as $key => $value) statement
The first form loops over the array given by array_expression. On each loop, the value of the current element is assigned to $value and the internal array pointer is advanced by one (so on the next loop, you'll be looking at the next element).
The second form does the same thing, except that the current element's key will be assigned to the variable $key on each loop.
Note: When foreach first starts executing, the internal array pointer is automatically reset to the first element of the array. This means that you do not need to call reset() before a foreach loop.
Note: Also note that foreach operates on a copy of the specified array, not the array itself, therefore the array pointer is not modified like with the each construct.
You may have noticed that the following are functionally identical:
reset ($arr);
while (list(, $value) = each ($arr)) {
echo "Value: $value
\n";
}

foreach ($arr as $value) {
echo "Value: $value
\n";
}
The following are also functionally identical:
reset ($arr);
while (list($key, $value) = each ($arr)) {
echo "Key: $key; Value: $value
\n";
}

foreach ($arr as $key => $value) {
echo "Key: $key; Value: $value
\n";
}
Some more examples to demonstrate usages:
/* foreach example 1: value only */

$a = array (1, 2, 3, 17);

foreach ($a as $v) {
print "Current value of \$a: $v.\n";
}

/* foreach example 2: value (with key printed for illustration) */

$a = array (1, 2, 3, 17);

$i = 0; /* for illustrative purposes only */

foreach($a as $v) {
print "\$a[$i] => $v.\n";
}

/* foreach example 3: key and value */

$a = array (
"one" => 1,
"two" => 2,
"three" => 3,
"seventeen" => 17
);

foreach($a as $k => $v) {
print "\$a[$k] => $v.\n";
}
break
break ends execution of the current for, while, or switch structure. break accepts an optional numeric argument which tells it how many nested enclosing structures are to be broken out of.
$arr = array ('one', 'two', 'three', 'four', 'stop', 'five');
while (list (, $val) = each ($arr)) {
if ($val == 'stop') {
break; /* You could also write 'break 1;' here. */
}
echo "$val
\n";
}

/* Using the optional argument. */

$i = 0;
while (++$i) {
switch ($i) {
case 5:
echo "At 5
\n";
break 1; /* Exit only the switch. */
case 10:
echo "At 10; quitting
\n";
break 2; /* Exit the switch and the while. */
default:
break;
}
}
continue
continue is used within looping structures to skip the rest of the current loop iteration and continue execution at the beginning of the next iteration. continue accepts an optional numeric argument which tells it how many levels of enclosing loops it should skip to the end of.
while (list ($key, $value) = each ($arr)) {
if (!($key % 2)) { // skip odd members
continue;
}
do_something_odd ($value);
}

$i = 0;
while ($i++ < 5) {
echo "Outer
\n";
while (1) {
echo "  Middle
\n";
while (1) {
echo "  Inner
\n";
continue 3;
}
echo "This never gets output.
\n";
}
echo "Neither does this.
\n";
}
switch
The switch statement is similar to a series of IF statements on the same expression. In many occasions, you may want to compare the same variable (or expression) with many different values, and execute a different piece of code depending on which value it equals to. This is exactly what the switch statement is for.
The following two examples are two different ways to write the same thing, one using a series of if statements, and the other using the switch statement:
if ($i == 0) {
print "i equals 0";
}
if ($i == 1) {
print "i equals 1";
}
if ($i == 2) {
print "i equals 2";
}
switch ($i) {
case 0:
print "i equals 0";
break;
case 1:
print "i equals 1";
break;
case 2:
print "i equals 2";
break;
}
It is important to understand how the switch statement is executed in order to avoid mistakes. The switch statement executes line by line (actually, statement by statement). In the beginning, no code is executed. Only when a case statement is found with a value that matches the value of the switch expression does PHP begin to execute the statements. PHP continues to execute the statements until the end of the switch block, or the first time it sees a break statement. If you don't write a break statement at the end of a case's statement list, PHP will go on executing the statements of the following case. For example:
switch ($i) {
case 0:
print "i equals 0";
case 1:
print "i equals 1";
case 2:
print "i equals 2";
}
Here, if $i equals to 0, PHP would execute all of the print statements! If $i equals to 1, PHP would execute the last two print statements, and only if $i equals to 2, you'd get the 'expected' behavior and only 'i equals 2' would be displayed. So, it's important not to forget break statements (even though you may want to avoid supplying them on purpose under certain circumstances).
In a switch statement, the condition is evaluated only once and the result is compared to each case statement. In an elseif statement, the condition is evaluated again. If your condition is more complicated than a simple compare and/or is in a tight loop, a switch may be faster.
The statement list for a case can also be empty, which simply passes control into the statement list for the next case.
switch ($i) {
case 0:
case 1:
case 2:
print "i is less than 3 but not negative";
break;
case 3:
print "i is 3";
}
A special case is the default case. This case matches anything that wasn't matched by the other cases, and should be the last case statement. For example:
switch ($i) {
case 0:
print "i equals 0";
break;
case 1:
print "i equals 1";
break;
case 2:
print "i equals 2";
break;
default:
print "i is not equal to 0, 1 or 2";
}
The case expression may be any expression that evaluates to a simple type, that is, integer or floating-point numbers and strings. Arrays or objects cannot be used here unless they are dereferenced to a simple type.
The alternative syntax for control structures is supported with switches.
switch ($i):
case 0:
print "i equals 0";
break;
case 1:
print "i equals 1";
break;
case 2:
print "i equals 2";
break;
default:
print "i is not equal to 0, 1 or 2";
endswitch;
require()
The require() statement replaces itself with the specified file, much like the C preprocessor's #include works.
If "URL fopen wrappers" are enabled in PHP (which they are in the default configuration), you can specify the file to be require()ed using an URL instead of a local pathname. See Remote files and fopen() for more information.
An important note about how this works is that when a file is include()ed or require()ed, parsing drops out of PHP mode and into HTML mode at the beginning of the target file, and resumes PHP mode again at the end. For this reason, any code inside the target file which should be executed as PHP code must be enclosed within valid PHP start and end tags.
require() is not actually a function in PHP; rather, it is a language construct. It is subject to some different rules than functions are. For instance, require() is not subject to any containing control structures. For another, it does not return any value; attempting to read a return value from a require() call results in a parse error.
Unlike include(), require() will always read in the target file, even if the line it's on never executes. If you want to conditionally include a file, use include(). The conditional statement won't affect the require(). However, if the line on which the require() occurs is not executed, neither will any of the code in the target file be executed.
Similarly, looping structures do not affect the behaviour of require(). Although the code contained in the target file is still subject to the loop, the require() itself happens only once.
This means that you can't put a require() statement inside of a loop structure and expect it to include the contents of a different file on each iteration. To do that, use an include() statement.
require ('header.inc');
When a file is require()ed, the code it contains inherits the variable scope of the line on which the require() occurs. Any variables available at that line in the calling file will be available within the called file. If the require() occurs inside a function within the calling file, then all of the code contained in the called file will behave as though it had been defined inside that function.
If the require()ed file is called via HTTP using the fopen wrappers, and if the target server interprets the target file as PHP code, variables may be passed to the require()ed file using an URL request string as used with HTTP GET. This is not strictly speaking the same thing as require()ing the file and having it inherit the parent file's variable scope; the script is actually being run on the remote server and the result is then being included into the local script.
/* This example assumes that someserver is configured to parse .php
* files and not .txt files. Also, 'works' here means that the variables
* $varone and $vartwo are available within the require()ed file. */

/* Won't work; file.txt wasn't handled by someserver. */
require ("http://someserver/file.txt?varone=1&vartwo=2");

/* Won't work; looks for a file named 'file.php?varone=1&vartwo=2'
* on the local filesystem. */
require ("file.php?varone=1&vartwo=2");

/* Works. */
require ("http://someserver/file.php?varone=1&vartwo=2");

$varone = 1;
$vartwo = 2;
require ("file.txt"); /* Works. */
require ("file.php"); /* Works. */
In PHP 3, it is possible to execute a return statement inside a require()ed file, as long as that statement occurs in the global scope of the require()ed file. It may not occur within any block (meaning inside braces ({}). In PHP 4, however, this ability has been discontinued.
include()
The include() statement includes and evaluates the specified file.
If "URL fopen wrappers" are enabled in PHP (which they are in the default configuration), you can specify the file to be include()ed using an URL instead of a local pathname. See Remote files and fopen() for more information.
An important note about how this works is that when a file is include()ed or require()ed, parsing drops out of PHP mode and into HTML mode at the beginning of the target file, and resumes again at the end. For this reason, any code inside the target file which should be executed as PHP code must be enclosed within valid PHP start and end tags.
This happens each time the include() statement is encountered, so you can use an include() statement within a looping structure to include a number of different files.
$files = array ('first.inc', 'second.inc', 'third.inc');
for ($i = 0; $i < count($files); $i++) {
include $files[$i];
}
include() differs from require() in that the include statement is re-evaluated each time it is encountered (and only when it is being executed), whereas the require() statement is replaced by the required file when it is first encountered, whether the contents of the file will be evaluated or not (for example, if it is inside an if statement whose condition evaluated to false).
Because include() is a special language construct, you must enclose it within a statement block if it is inside a conditional block.
/* This is WRONG and will not work as desired. */
if ($condition)
include($file);
else
include($other);
/* This is CORRECT. */
if ($condition) {
include($file);
} else {
include($other);
}
In both PHP 3 and PHP 4, it is possible to execute a return statement inside an include()ed file, in order to terminate processing in that file and return to the script which called it. Some differences in the way this works exist, however. The first is that in PHP 3, the return may not appear inside a block unless it's a function block, in which case the return applies to that function and not the whole file. In PHP 4, however, this restriction does not exist. Also, PHP 4 allows you to return values from include()ed files. You can take the value of the include() call as you would a normal function. This generates a parse error in PHP 3.
When a file is include()ed, the code it contains inherits the variable scope of the line on which the include() occurs. Any variables available at that line in the calling file will be available within the called file. If the include() occurs inside a function within the calling file, then all of the code contained in the called file will behave as though it had been defined inside that function.
If the include()ed file is called via HTTP using the fopen wrappers, and if the target server interprets the target file as PHP code, variables may be passed to the include()ed file using an URL request string as used with HTTP GET. This is not strictly speaking the same thing as include()ing the file and having it inherit the parent file's variable scope; the script is actually being run on the remote server and the result is then being included into the local script.
/* This example assumes that someserver is configured to parse .php
* files and not .txt files. Also, 'works' here means that the variables
* $varone and $vartwo are available within the include()ed file. */

/* Won't work; file.txt wasn't handled by someserver. */
include ("http://someserver/file.txt?varone=1&vartwo=2");

/* Won't work; looks for a file named 'file.php?varone=1&vartwo=2'
* on the local filesystem. */
include ("file.php?varone=1&vartwo=2");

/* Works. */
include ("http://someserver/file.php?varone=1&vartwo=2");

$varone = 1;
$vartwo = 2;
include ("file.txt"); /* Works. */
include ("file.php"); /* Works. */
require_once()
The require_once() statement replaces itself with the specified file, much like the C preprocessor's #include works, and in that respect is similar to the require() statement. The main difference is that in an inclusion chain, the use of require_once() will assure that the code is added to your script only once, and avoid clashes with variable values or function names that can happen.
For example, if you create the following 2 include files utils.inc and foolib.inc
utils.inc
define(PHPVERSION, floor(phpversion()));
echo "GLOBALS ARE NICE\n";
function goodTea() {
return "Oolong tea tastes good!";
}
?>

foolib.inc
require ("utils.inc");
function showVar($var) {
if (PHPVERSION == 4) {
print_r($var);
} else {
var_dump($var);
}
}

// bunch of other functions ...
?>

And then you write a script cause_error_require.php
cause_error_require.php
require("foolib.inc");
/* the following will generate an error */
require("utils.inc");
$foo = array("1",array("complex","quaternion"));
echo "this is requiring utils.inc again which is also\n";
echo "required in foolib.inc\n";
echo "Running goodTea: ".goodTea()."\n";
echo "Printing foo: \n";
showVar($foo);
?>

When you try running the latter one, the resulting ouptut will be (using PHP 4.01pl2):
GLOBALS ARE NICE
GLOBALS ARE NICE

Fatal error: Cannot redeclare goodTea() in utils.inc on line 5
By modifying foolib.inc and cause_errror_require.php to use require_once() instead of require() and renaming the last one to avoid_error_require_once.php, we have:
foolib.inc (fixed)
...
require_once("utils.inc");
function showVar($var) {
...

avoid_error_require_once.php
...
require_once("foolib.inc");
require_once("utils.inc");
$foo = array("1",array("complex","quaternion"));
...

And when running the latter, the output will be (using PHP 4.0.1pl2):
GLOBALS ARE NICE
this is requiring globals.inc again which is also
required in foolib.inc
Running goodTea: Oolong tea tastes good!
Printing foo:
Array
(
[0] => 1
[1] => Array
(
[0] => complex
[1] => quaternion
)

)
Also note that, analogous to the behavior of the #include of the C preprocessor, this statement acts at "compile time", e.g. when the script is parsed and before it is executed, and should not be used for parts of the script that need to be inserted dynamically during its execution. You should use include_once() or include() for that purpose.
For more examples on using require_once() and include_once(), look at the PEAR code included in the latest PHP source code distributions.
include_once()
The include_once() statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the include() statement, with the important difference that if the code from a file has already been included, it will not be included again.
As mentioned in the require_once() description, the include_once() should be used in the cases in which the same file might be included and evaluated more than once during a particular execution of a script, and you want to be sure that it is included exactly once to avoid problems with function redefinitions, variable value reassignments, etc.
Finaly our arrengement about control structure finished. Are you confused about what im talking about? I know when there is a will there is a way. With study hard Im sure you can understand and apply the knowledge in your life. In the next chapter I will easied up a subject about function inluding the user defined function, function arguments etc.
Chapter 6
Title : PHP Programing | PHP Basic | chapter 6 Functions
User-defined functions
A function may be defined using syntax such as the following:
function foo ($arg_1, $arg_2, ..., $arg_n) {
echo "Example function.\n";
return $retval;
}
Any valid PHP code may appear inside a function, even other functions and class definitions.
In PHP 3, functions must be defined before they are referenced. No such requirement exists in PHP 4.
PHP does not support function overloading, nor is it possible to undefine or redefine previously-declared functions.
PHP 3 does not support variable numbers of arguments to functions, although default arguments are supported (see Default argument values for more information). PHP 4 supports both: see Variable-length argument lists and the function references for func_num_args(), func_get_arg(), and func_get_args() for more information.
Function arguments
Information may be passed to functions via the argument list, which is a comma-delimited list of variables and/or constants.
PHP supports passing arguments by value (the default), passing by reference, and default argument values. Variable-length argument lists are supported only in PHP 4 and later; see Variable-length argument lists and the function references for func_num_args(), func_get_arg(), and func_get_args() for more information. A similar effect can be achieved in PHP 3 by passing an array of arguments to a function:
function takes_array($input) {
echo "$input[0] + $input[1] = ", $input[0]+$input[1];
}
Making arguments be passed by reference
By default, function arguments are passed by value (so that if you change the value of the argument within the function, it does not get changed outside of the function). If you wish to allow a function to modify its arguments, you must pass them by reference.
If you want an argument to a function to always be passed by reference, you can prepend an ampersand (&) to the argument name in the function definition:
function add_some_extra(&$string) {
$string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str; // outputs 'This is a string, and something extra.'
If you wish to pass a variable by reference to a function which does not do this by default, you may prepend an ampersand to the argument name in the function call:
function foo ($bar) {
$bar .= ' and something extra.';
}
$str = 'This is a string, ';
foo ($str);
echo $str; // outputs 'This is a string, '
foo (&$str);
echo $str; // outputs 'This is a string, and something extra.'
Default argument values
A function may define C++-style default values for scalar arguments as follows:
function makecoffee ($type = "cappucino") {
return "Making a cup of $type.\n";
}
echo makecoffee ();
echo makecoffee ("espresso");
The output from the above snippet is:
Making a cup of cappucino.
Making a cup of espresso.
The default value must be a constant expression, not (for example) a variable or class member.
Note that when using default arguments, any defaults should be on the right side of any non-default arguments; otherwise, things will not work as expected. Consider the following code snippet:
function makeyogurt ($type = "acidophilus", $flavour) {
return "Making a bowl of $type $flavour.\n";
}
echo makeyogurt ("raspberry"); // won't work as expected
The output of the above example is:
Warning: Missing argument 2 in call to makeyogurt() in
/usr/local/etc/httpd/htdocs/php3test/functest.html on line 41
Making a bowl of raspberry .
Now, compare the above with this:
function makeyogurt ($flavour, $type = "acidophilus") {
return "Making a bowl of $type $flavour.\n";
}
echo makeyogurt ("raspberry"); // works as expected
The output of this example is:
Making a bowl of acidophilus raspberry.
Variable-length argument lists
PHP 4 has support for variable-length argument lists in user-defined functions. This is really quite easy, using the func_num_args(), func_get_arg(), and func_get_args() functions.
No special syntax is required, and argument lists may still be explicitly provided with function definitions and will behave as normal.
Returning values
Values are returned by using the optional return statement. Any type may be returned, including lists and objects.
function square ($num) {
return $num * $num;
}
echo square (4); // outputs '16'.
You can't return multiple values from a function, but similar results can be obtained by returning a list.
function small_numbers() {
return array (0, 1, 2);
}
list ($zero, $one, $two) = small_numbers();
To return a reference from a function, you have to use the reference operator & in both the function declaration and when assigning the returned value to a variable:
function &returns_reference() {
return $someref;
}

$newref =&returns_reference();
Variable functions
PHP supports the concept of variable functions. This means that if a variable name has parentheses appended to it, PHP will look for a function with the same name as whatever the variable evaluates to, and will attempt to execute it. Among other things, this can be used to implement callbacks, function tables, and so forth.
Variable function example
function foo() {
echo "In foo()
\n";
}

function bar( $arg = '' ) {
echo "In bar(); argument was '$arg'.
\n";
}

$func = 'foo';
$func();
$func = 'bar';
$func( 'test' );
?> Readmore »»

Blog Archive

get update

 Subscribe in a reader

Enter your email address:

Delivered by FeedBurner