UnitedForums - UK Web Hosting Forum UnitedHosting Community Hosting Forums
Network and Server StatusCustomer SupportUK Web Hosting
UnitedHostingUnitedHosting Sitemap UK Hosting ForumUK Web HostingWeb Hosting ForumsUK Reseller HostingWeb Host CommunityUK Managed Dedicated ServersHosting Help and SupportUK Domain Name Registration

Go Back   UnitedForums.co.uk > UnitedHosting Community > Website Development & Scripting

Reply
 
Thread Tools Rate Thread Display Modes
Old 18th April 2005, 10:56 AM   #1 (permalink)
Bech100
Senior Member
 
Bech100's Avatar
 
Join Date: Feb 2005
Location: York, UK
Posts: 144
PHP Starter Pack - Fundamental PHP Know-How

We compiled this on our PHPDevnet forum, thought it may also be useful here!?

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

--------------------------------------------------------------------

Install a local server (for testing purposes):

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://www.hotscripts.com/PHP/Softwa...allation_Kits/

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

Mac users may find that they don't have a php.ini to edit. See these forum topics: http://forums.devnetwork.net/viewtopic.php?t=11017
http://forums.devnetwork.net/viewtopic.php?t=3916).


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://www.webmasterstop.com/tutoria...c-quotes.shtml. 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 http://www.phpmyadmin.net/. Other db managers worth a look are SQLyog: http://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 http://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://www.zend.com/zend/tut/using-strings.php might be a good place to start.

We have our own PHP Wiki. At the time of writing this has just been launched but should grow into a comprehensive php knowledgebase.

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://freebsd.mu/freebsd/archives/000039.html

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://www.devshed.com/Server_Side/MySQL
http://www.oreilly.de/catalog/javadt...apter/ch02.pdf

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

Phpcomplete.com http://www.phpcomplete.com 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://www.php.net/manual/en/pcre.pattern.syntax.php

And here's a useful little tool to test expressions: http://www.weitz.de/regex-coach/#install

Php Scripts & Programs

The Evilwalrus script repository http://www.evilwalrus.com/ 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.
__________________
Mark | PHP DevNetwork Administrator
Senior Web Developer
Bech100 is offline   Reply With Quote
Old 18th April 2005, 11:58 AM   #2 (permalink)
UH-Matt
Administrator
 
UH-Matt's Avatar
 
Join Date: Oct 2002
Location: London, UK
Posts: 8,135
Awsome post - maybe I should make it sticky for a while!
__________________
.
Matt
UnitedHosting Staff

For official support please use our helpdesk at UnitedSupport.co.uk

UnitedHosting proudly hosting more than 20,000 sites since 1998.
UH-Matt is offline   Reply With Quote
Old 18th April 2005, 04:38 PM   #3 (permalink)
leafish_paul
web monkey
 
leafish_paul's Avatar
 
Join Date: Apr 2003
Location: North Wales
Posts: 331
Send a message via ICQ to leafish_paul Send a message via MSN to leafish_paul
Some great info and links there. How about sticking some of it in this tutorial?
__________________
paul byrne - web monkey
paul.leafish.co.uk | www.leafish.co.uk
leafish_paul is offline   Reply With Quote
Old 18th April 2005, 11:52 PM   #4 (permalink)
richandzhaoyan
Senior Member
 
Join Date: Apr 2004
Location: Stroud, Gloucestershire
Posts: 426
Yep, thanks from a php semi-novice, some very good information and just what I like to find in these forums. Very useful.

I just hope I find the time to follow a few more of the links you have posted!

Cheers,
Rich
__________________
Only Dead Fish go with the Flow....
shopping2buyonline.com
richandzhaoyan is offline   Reply With Quote
Old 20th April 2005, 03:48 PM   #5 (permalink)
Pablo
Registered User
 
Join Date: Mar 2005
Posts: 18
While you were posting this, I was attending a php/MySQL training course which really left me wanting to play around with some scripts, so this couldn't be better timed.

Many thanks.
Pablo is offline   Reply With Quote
Old 7th May 2005, 03:30 PM   #6 (permalink)
Dave
Registered User
 
Join Date: May 2005
Posts: 18
A few musings:

I have no experience at all of 'all-in-one' Apache-PHP-MySQL packages, but anyone who is moderately tech-savvy can easily download and set up all three (with the help of some light googling). At the expense of learning a little of how the software works, you will be able to keep yourself properly up to date and probably be a lot more confident tweaking your configurations. A worthwhile investment IMHO.

PostgreSQL - it is massively better than MySQL (although slower - not that localhost developers are going to notice). More relevant is the fact that it has very poor support from web hosting companies - SQL is SQL but your connection routines etc. will change if you aren't using some form of abstraction. Changing between local / remote database types is an unnecessary complication so I probably wouldn't recommend postgres for beginners.

Actually learning SQL - There is a lot to learn, although most of it (BCNF and other normal forms, indexing, transactions, alternate table types, etc) isn't relevant to beginners. I wouldn't recommend moving onto these things until a solid understanding of basic database use has been achieved. There are, thankfully, thousands of introductary SQL tutorials strewn across the web.

I feel similarly about regex (use the alternative functions if you can), buffering, custom error handlers and all the rest - there's a lot to learn first!

This is contentious, but my recommendation (as a Java developer who knows his way around PHP) is to steer clear of objects as long as you can. They're almost always redundant in a website script, and my honest opinion is that if your site is complex enough to benefit from objects, it's certainly going to benefit from strong typing and all the other advantages that you'd get by switching to Java (or .NET)

PHP scripts - you'll learn much faster writing your own code! That said, referring to scripts is a good way to kickstart your understanding of a given technique in action (just remember that free script writers aren't renowned for their skill - you could pick up bad habits!)

Most of all, enjoy yourself, and don't be afraid to ask for help!
Dave is offline   Reply With Quote
Old 12th May 2005, 03:22 PM   #7 (permalink)
Pablo
Registered User
 
Join Date: Mar 2005
Posts: 18
Using the links above I tried installing Apache2 triad, which seemed to install and run but then kind of sat there and did nothing. Probably my fault, I dunno.

I then moved on to Friends of Apache's XAMMP installation, which was a really easy download and installation and works fine but won't connect with MySQL unless I switch off my firewall [ZoneLabs]. Any suggestions on getting round this?

Other than that, I'm thrilled to be able to play around with php and databases [though I have to admit i haven't got very far yet].

Thanks again.
Pablo is offline   Reply With Quote
Old 15th May 2005, 12:43 PM   #8 (permalink)
Dave
Registered User
 
Join Date: May 2005
Posts: 18
Open up port 3306. Named pipes is a better option, but that's the simple solution.

D.
Dave is offline   Reply With Quote
Old 31st October 2008, 07:15 AM   #9 (permalink)
Open Source
Registered User
 
Join Date: Oct 2008
Posts: 1
PHP Starter Pack - Fundamental PHP Know-How

I also use Macromedia Dreamweaver for editing. And it is well working for me. I also use notepad for it. So I have no problem for development. Thanks for sharing this post. Keep it up
__________________
WIFI
Open Source is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


All times are GMT. The time now is 08:43 PM.

UK Web Hosting  |  UK Reseller Hosting  |  UK Dedicated Servers UnitedHosting  |  UnitedSupport  |  UnitedForums  |  SEO by vBSEO 3.0.0
Copyright © 1998-2008 United Communications Limited. All Rights Reserved. Registered in England and Wales 3651923 - VAT Reg No. 737662309