Getting into PHP

Why did I get into learning PHP? Because I wanted to understand how a website was built correctly. I had a old website with blogging software from b2evolution, gallery from coppermine and couple of static pages put together not knowing how the code worked. So to upgrade things I started to learn how a website was built & developed, and what technologies were required.

The first part was to understand (X)HTML & CSS and then from that point you can go on to learn PHP with MySQL. You can find many tutorials online as an example of a resource of PHP tutorials at Nettuts. I also find buying an old book was very good as it meant that I was learning in a more structured manor then if I used online tutorials. So the book I brought was PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide and also PHP 5 Advanced: Visual QuickPro Guide (2nd Edition).

I have now finished the first book and will be finally starting work on my first PHP & Mysql application

Using PHP mail function on Localhost Only

If you are testing the PHP mail function mail( ) running from your own localhost and you do not what to run your own mail server this may help.

I was testing a PHP activation script that would send a email to another email to activate the new users account. My environment is all ran locally, and I had no desire to set-up a proper configure mail server or use Pear mail.

So to get around this problem I installed webmin so that I could easily access postfix mail server and to receive the email.

Install Webmin

Download webmin

Install Webmin
sudo dpkg -i webmin_1.340_all.deb

Once installed you can log into webmin using your root password.

Now when sending the activation email insure that you send it to root@locahost, do not include .com or . anything as this did not work for me.

If you have any validation within your script make sure everything relation to email validation is changed.

Changing PHP validation (preg_match)

Normal Validation in php
(preg_match (‘/^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/’,)

Changed Validation
(preg_match (‘/^[\w.-]+@[\w.-]/’,)

Once you do this you should be able to access the email via webmin within the postfix module. Goto servers, users mailbox, select root or your system user name.

MySQL University

Came across this the other day, it’s the MySQL University that offers free educational online program for engineers/developers. It’s open to everyone to just join in by using DimDim, a web based conference tool build in Flash.

The session room opens 15 minutes before the live sessions starts, but you can also catch up on previous shows if like me you probably will not be able to catch the live session. Go here for list of previous sessions

For more information and please visit the MySQL University homepage

Perl Compatible Regular Expressions – Classes & Shortcuts

If you are playing around with PCRE in php and are you having problems with using character classes or shortcuts, remember to check your php.ini file.

I was having problems and after much head starching, i found out that you have to disable magic quotes in the php.ini file. So run phpinfo() to locate the file and then ensure the below is set to “Off”.You could use stripslashes() within preg_match() to stop extra “\” being generated. But that is really extra code that you do not need.

; Magic quotes

; Magic quotes for incoming GET/POST/Cookie data.
magic_quotes_gpc = Off

; Magic quotes for runtime-generated data, e.g. data from SQL, from exec(), etc.
magic_quotes_runtime = Off

; Use Sybase-style magic quotes (escape ‘ with ” instead of \’).
magic_quotes_sybase = Off

Cannot modify header information

I have been working on making a login page as part of learning php. This method also included using cookies, not everyones favorite but I had to learn about it. The thing with cookies is that they must be sent from the server to the client prior to any other information.

This was the area that was creating my problem, every time I logged in I would get this error.

Cannot modify header information – headers already sent by (output started at /var/mysqli_connect.php:18)

This is a common error when creating cookies. So pay attention to the error message, which is something I did not do straight away. All I had to do was delete any white space after my closing ?> in mysql_connect file.

PhP & Mysql update

Been making slow but steady progress with php & mysql learning this month. I feel that things are starting to fall into place and soon I’m going to start work on my first project.

It’s going to be php & mysql based links/bookmarks page for the main basshead website. Currently it’s an old static page that was put together a few years ago before I had a clue about basic structure of HTML etc. I could use scuttle as used by weloveit on they bookmarks site, but it’s something I would like to write from start to finish as it would be a good learning platform. Also this will start life as a page for basshead links/bookmarks that can only be updated by myself as I will not be allowing anyone else to input bookmarks as it is not a social networking bookmark system like scuttle. If this project works out ok then anyone can use it, and change it so it becomes social networking based.