Jump to content
xisto Community
Sign in to follow this  
illusion

Fundamental Php Know-how

Recommended Posts

This tutorial is aimed at people taking their first steps with php.

 

Install a local server:

 

A local development server is essential to test out your work. GNU/Linux & BSD (except mac) usually have a web server already set up. For others, there are lots of options with php/mysql/apache in a single, easy to install package. I use easyphp. Other options at:

 

http://forums.xisto.com/no_longer_exists/

php.ini settings

Once you've installed php/mysql/apache, I'd recommend checking the following in your php.ini file:

 

error_reporting = E_ALL

display_errors = On

register globals off (it's off by default for php v4.2+)

magic_quotes_gpc - see notes, below

magic_quotes_runtime - off

 

Note that you should turn the error reporting level down on a live site to avoid giving out information about your scripts or db structure which a hacker might try to exploit.

 

Register globals on can potentially create a security risk. If you have any undefined vars/indexes in the script, a site visitor can set them to any value they like (more here). However if you develop with E_ALL you will (presumably) have identified any such and dealt with them, so register globals on would not create any security issues.

 

Many hosts keep reg globals on for backwards compatibility. Scripts developed with reg globals off will work OK in a reg globals on environment - but not vice versa. So, quite apart from possible security issues, it's better to develop with reg globals off. One day your host will upgrade and your old scripts won't work.

 

Magic quotes on might be viewed as a useful safety net for inexperienced programmers. Personally, I think that Magic Quotes are Evil: http://forums.xisto.com/no_longer_exists/. It's your call.

 

Unlike register globals, a script which works with magic_quotes_gpc off won't work perfectly with it on. The "pro" way is to always set magic quotes off - local and live (if you can) - as well as applying the fix (see above link) to distributed programs which might be run in other environments.

Database Managers

You probably got the excellent phpMyadmin with one of the php/mysql/apache packages above. If not see https://www.phpmyadmin.net/. Other db managers worth a look are SQLyog: https://www.webyog.com/ and

Aqua http://www.aquafold.com/index.html

Manuals

You can view the online manual at php.net. There are also downloadable versions for those of us who still don't have broadband. I'd recommend the version with user comments. Essential reading - but note that user comments are not always correct. The ones that aren't will usually be picked up on.

Apache info: http://www.apache.org/

Mysql.com - as with php.net, online and downloadable manuals here.

Of course php works with all kinds of databases, including the more powerful https://www.postgresql.org/ .

Script editors

A proper script editor with syntax highlighting, cliptext, find in files, etc makes life much easier. EditPlus is an inexpensive favourite for many. Htmlkit is free. BBedit for the mac and vim for linux are other popular choices. If your bank balance is up to it, take a look at Zend developer studio.

Php Tutorials

The internet is a fantastic resource for php tutorials. This one from Zend: http://forums.xisto.com/no_longer_exists/ might be a good place to start.

 

 

 

Many good tutorials on these sites:

Zend.com

O'reilly

 

A variety of internet related tutorials as well as php here: http://www.w3schools.com/

 

And check out the links on php.net.

 

If all that was too basic try this: http://forums.xisto.com/no_longer_exists/

Database Tutorials

Database design is often neglected but it's the essential foundation of a php web site. Table joins, normal forms: you've got to know it all.

http://forums.xisto.com/no_longer_exists/

http://www.oreilly.de/book_details.php?masterid=

 

For a general and hands-on excellent SQL-tutorial: http://sqlzoo.net/wiki/Main_Page

 

Phpcomplete.com http://forums.xisto.com/no_longer_exists/ has several PostgreSql tutorials.

Coding Styles

Coding styles are a matter of personal preference but it's best to follow common practices as far as possible. One day you might be working in a team or at the very least you're going to be asking for help on the forums. Other people will have to figure out what you're code is doing so a consistent style is a good habit to get into from the start.

 

Personally I follow most of the PEAR guidelines: http://pear.php.net/manual/en/standards.php

Regex

You may find regular expressions (regex) to be a mind-bendingly frustrating experience. Don't worry: that's normal. Regex'ing was invented by evil madmen for that very purpose.

 

The good news is that you can often use one of the string functions - eg str_replace(), substr() etc - instead. These are preferred since they are slightly faster. You'll rarely need the extra power of regex.

 

The posix ereg(), eregi() functions are marginally slower than perl-style preg_match, preg_replace etc and so the latter are preferred.

 

Syntax is explained in the manual http://forums.xisto.com/no_longer_exists/

 

And here's a useful little tool to test expressions: http://forums.xisto.com/no_longer_exists/

Php Scripts & Programs

The Evilwalrus script repository http://www.evilwalrus.com//?gtnjs=1 has many php scripts to download. You can use these in your own programs or read through them to get some ideas.

 

There are thousands of php programs available for free at hotscripts.com.

 

One day, when you start mucking about with OOP (object orientated programming), you might want to take a look at another phpdn site: phpclasses.com. Also, phppatterns.com is an excellent source for OOP design.

Help

If you've got a problem the first step is to get the manual out. The manual is your best friend. Love it, cherish it and, above all, read it.

 

Next try a forum search: there's a wealth of information in here and there's a good chance your problem has been dealt with before.

 

If that doesn't work, pick the appropriate forum and post a message.

 

The art of asking good questions: http://www.catb.org/~esr/faqs/smart-questions.html

 

On our discussion boards, the focus is more on helping people to learn rather than simply handing out working scripts. Someone who is making a real effort to tackle a problem is much more likely to receive help than a "please can anyone give me a file upload script" type of post.

 

If you post code, don't forget to use the [ php] BB code tags: syntax highlighting & proper indentation makes it much easier to read - and so more likely that you'll get a response.

Share this post


Link to post
Share on other sites

Hey Illusion, I FoRmAtEd your above post to make it more clear.. nice tutorial keep it up.So far as php is concerned, Whenever I start coding, I keep the manual open. You can download the chm version ( very handy ) from their site. Its simply great with lot of examples.A basic knowledge of any other language will help you to kickstart php.

Share this post


Link to post
Share on other sites

I know that this isn't about webservers, but a quick link fo those that want to get the dirty work of getting php to work on their local M$ machine:

You can use OmniSecure.

It comes with PHP already installed and supported...

Share this post


Link to post
Share on other sites

I liked it a lot. This was an instuctional "How to" that helps a novice like me to start playing with php.I'm just starting with webcreations and dB for we so the beginner tutorials like this one will put us on the right path.I'll setup a new computer (old one) over the new year and see if I can start playing with all I have learned here over the last coulpe of days.I have to say there are a lot of difference (and they are a like) between managing a network and managing a website. illusion, thanks again, a + point to you.Nils

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.