Tag Archive for 'PHP'

Learn PHP: Class Three

If you're new here, you may want to subscribe to my RSS feed. This would mean that you'll never miss a post! You can also subscribe via email if you look in the sidebar!
Thanks for visiting!
Sean

Table of contents for Learn PHP

  1. Learn PHP: Prep
  2. Learn PHP: Class One
  3. Learn PHP: Class Two
  4. Learn PHP: Class Three

Today we are going to learn all about include and require! Include and require are handy to use not only in your php applications, but in general website design for sidebar’s and what not! So.. yeah.. :P Moving on!

Include and Require include a file within another PHP script. There are four ways of doing this:

  • include();
  • include_once();
  • require();
  • require_once();

Now using them is seriously simple. Lets say you have sidebar.php with your links? All you have do do is the following:

<?php include(”sidebar.php”); ?>

One thing to remember is how to control directories in PHP. For instance, if my file “sidebar.php” is in a folder called includes you put in:

<?php include(”includes/sidebar.php”); ?>

Or to take another route of it, if my file “sidebar.php” is in the / directory and the file I want the sidebar to show on is in a folder of that: /data I would put in:

<?php include(”../sidebar.php”); ?>

Now why are there four different ways to include them I hear you ask! Well they are pretty simple.

Include and Require are practically the same, apart from the way they give out errors. Include will continue parsing your script and just shove out an error. Require however will stop the whole script to give you an error. Really it’s all down to what you want.

Include_once and require_once you probably guess only allow you to include the file once. This is not only more secure but stops from silly errors where the file was just included and variables were overwritten halfway through the script. Again they give out the same errors as include and require.

So lets go over one of each!

<?php include(”sidebar.php”); ?>

<?php include_once(”sidebar.php”);?>

<?php require(”sidebar.php”);?>

<?php require_once(”sidebar.php”);?>

We really are spoilt for choice aren’t we! ;)


If you liked this post, perhaps you'd like to buy me a coffee?

Learn PHP: Class Two

Table of contents for Learn PHP

  1. Learn PHP: Prep
  2. Learn PHP: Class One
  3. Learn PHP: Class Two
  4. Learn PHP: Class Three

Moving on to Class II after a long break! We will today cover PHP’s If Else Statements.

Here is one in action:

<?php
if ($condition) {
echo “condition is true”;
}
?>

Simple enough? To start with as you can see you first write the statement name, in this case “if”. Then you enclose your condition in brackets, [A condition is essentially a question you ask PHP.] then you add an opening “curly bracket”. The opening curly bracket basically defines the start of the code to execute of the condition of the statement evaluates to true. In this case we are wanting PHP to output the text “condition is true” if the condition is true. Then finally we have a closing curly bracket.
In the above example the entire condition has simply been set to the variable $condition. Therefore what we are asking PHP is does the variable $condition exist, and if it does, does it have a value that is not NULL. [Null = Nothing, zero, zilch] In this case we didn’t actually define the variable $condition therefore the statement will evaluate to false and the code within the statement wont be executed. Therefore the above will output nothing at all. However the following code:

<?php
$condition = “Here!”
if ($condition) {
echo “condition is true”;
}
?>

Would output “Condition is True”.

Now if statements are pretty useless on their own! What you really want is if / else statements, which we will look at here!

<?php
$condition = 10;
if ($condition == 5) {
echo “condition is 5″;
}
?>

Basically here the variable condition is 10. PHP Checks if it is 5. As we all know 10 is not 5, so PHP does nothing. However in this statement:

<?php
$condition = 10;
if ($condition == 5) {
echo “condition is 5″;
} else if ($condition < 5) {
echo “condition is less than 5″;
} else {
echo “condition is ” . $condition;
}
?>

We have an if statement, an if else statement and an else statement.
Basically the code explains it, but the condition is 10. If the condition is 5, PHP will output that it is 5. Otherwise if the condition is less than 5. PHP will output that it is less than five. Lastly, if nothing matches in the if or else if statements PHP will output its else. Saying Condition is 10.

A last sample before we head off.

<?php
$condition = “yes”;
if ($condition == “no”){
echo “condition is false”;
} else if ($condition == “yes”){
echo “condition is true”;
} else {
echo “Something happened to the variable”;
}
?>

Here you can see that the condition is actually a word. PHP checks it just like it would a number and outputs all the same. Here PHP would output “Condition is True”.

And that’s it for today! Next week we have “arrays” so until then practise! :)


If you liked this post, perhaps you'd like to buy me a coffee?

Ruby on Rails vs PHP, Java & .NET

Ruby on Rails vs PHP

Ruby on Rails vs .NET

Ruby on Rails vs Java


If you liked this post, perhaps you'd like to buy me a coffee?

Learn PHP: Class One

Table of contents for Learn PHP

  1. Learn PHP: Prep
  2. Learn PHP: Class One
  3. Learn PHP: Class Two
  4. Learn PHP: Class Three


So now that we have done the Prep Class its time to move on to the actual learning!

PHP Class I.

Echo’ing:

<?php echo “text here”; ?>

OR

<?php echo ‘text here’; ?>

Simple as that, thats how you get PHP to output some text. Whichever you use is really up to you, there is pros and cons to what you can do with each, you can read about them here. I prefer the double quoted version, just because I’m used to it.

Comments:
Comments are really important within any programming language, really to tidy up your code and so you remember what each bit does later on. PHP supports two different ways of commenting, C++ Style and Shell style. I will just stick with C++ Style for today

Example’s of echo’ng via C++ Style are as follows:

<?php
echo “Hi”; // Output: Hi
echo “Hi”; /* Hi */
?>

// Comments out the rest of the line. While /* */ lets you comment as far as you want, just remember to close the comment! If you don’t get me I’ll do a quick example:
This stop PHP echo’ing “Hi”

<?php
/*
echo “Hi”;
*/
?>

This however will not.

<?php
//
echo “Hi”;
//
?>

But this would

<?php
//echo “Hi”;
?>

/* style are obviously much easier for commenting out blocks of code. But for just adding a quick comment // style is alot better!

Variables:

<?php
$variablename = “Variable One”;
$variablename = ‘Variable One’;
$variablename = 1;
?>

Variables are vital within your programming language, you will use them over and over again! Again, you can use single or double quotes, both with their pros and cons, you can also use numbers, or other variables. I’ll give you a quick example of adding within variables.

<?php
$add = 2 + 1;
?>

That variable would add 2 + 1. But how to get what the Variable says? Well you just use echo again!

<?php
$add = 2 + 1;
echo $add;
?>

The output of that would be:

3

Nothing more, nothing less.
You can also add variables within variables. As complicated as that sounds its pretty easy. I’ll give you a quick example.

<?php
$one = 1;
$two = 2;
$add = $one + $two;
echo $add;
?>

So lets go over what we just learnt with a quick script;

<?php
$name = “Sean”; // My Name
$age = 16 +1; // Seventeen!
$nextage = $age +1; //Age I will be next year.
echo ‘Hi my name is ‘;
echo $name;
echo ‘ and I am ‘;
echo $age;
echo ‘ but I will be ‘
echo $nextage;
echo ‘ next year!’
?>

Of course that is probably the longest, but easiest way you could do it! The faster way to do it would be:

<?php
$name = “Sean”; // My Name
$age = 16 +1; // Seventeen!
$nextage = $age +1; //Age I will be next year.
echo “Hi my name is $name and I am $age but I will be $nextage next year!”;
?>

That’s defiantly the handiest way to do it! Don’t worry I’ll go abit more into that in the next lesson! Until then, practice!


If you liked this post, perhaps you'd like to buy me a coffee?

Learn PHP: Prep

Table of contents for Learn PHP

  1. Learn PHP: Prep
  2. Learn PHP: Class One
  3. Learn PHP: Class Two
  4. Learn PHP: Class Three

PHP

Nearly two or three times every week I get someone asking me to teach them how to program, many of these are from an online game I help out with called Injustice. Its amazing really that people that there is some hidden secret to coding and that I can just send you a link or say one or two lines and they will be able to code! I’m telling you people, its not magic!!
So instead of repeating myself over and over I’m shoving this article in here! Mainly because of this, secondly because I believe people can learn PHP a little easier than some of the websites make it. So on with the show!

Ok, so to actually learn PHP the best way to do it will be to install Xampp.
You can download Xampp here.
Xampp will install Apache [Webserver] MySQL [Database] and PHP among other things, but that is all we will be using! Once you download the file, run it, its a graphical installer for windows. For linux users, I’m sure you can work out how to install it! ;) Once installed start the Apache and MySQL services, the control panel will be in front of you, all you have to do is tick the boxes! Yep thats it, your done installing. Now, to put files into your “webserver” you will go into C:/Xamp/ht_docs/ if you installed it in the default directory. So lets create a folder called project. And put a file called index.php in there. In the index.php file just put the word “Test”. Then all you have to do is go to, http://localhost/project/index.php and if you did everything right you should be looking at a webpage that just says “Test”. There you have it! You are ready to learn PHP!


If you liked this post, perhaps you'd like to buy me a coffee?

Werewolf IRC Bot

Well just doing a google search on “werewolf bot irc” I come up as the 2nd result, right after the buggy java version! So I figured I better make a post on it for people who come here looking for one. At the moment I am using a PHP based bot. [Probably not the best but it works] I’m going to change over to an EggBot version soon, as that’d be better but while you are all waiting for me to figure out how to do that the version I am using now is based on the PHP:IRC framework. You can download the framework here, and the mod for the werewolf mod here. [go for version 2.2 of the mod]

Really simple to setup, extract the framework, extract the bot.. shove the bot folder into the modules folder. Download PHP 5 the PHP 5.2.3 zip package..Extract it to C:/Php5/ [this just makes things easier] Move the Framework package to C://, rename it PHPirc. [Again, just simplifing things..]

Follow the readme on changing the php.ini parts of the files.. [the readme in the PHPirc folder]

Open your defines.php page 2nd or 3rd line

define(’OS’, ‘os’); - change it to Windows or Linux..

Open bot.conf, set your bots nickname and password and what not!

Open functions.conf, scroll to the bottom, replace the includes with this:

include typedefs.conf;include modules/default/priv_mod.conf

;include modules/default/dcc_mod.conf

include modules/werewolf/werewolf.conf

;include modules/bad_words/bad_words.conf

;include modules/peak_mod/peak_mod.conf

;include modules/seen/seen_mod.conf

;include modules/news/news_mod.conf

;include modules/imdb/imdb_mod.conf

;include modules/quotes_ini/quote_mod.conf

;include modules/quotes_sql/quote_mod.conf

;include modules/httpd/httpd_mod.conf

;include modules/fileserver/fileserver.conf

;include modules/bash/bash_mod.conf

Go, Start - Run,
Type in “cmd” [without the “’s]
a DOS window will open do the following commands:

cd C:/PhpIRCC:/php5/php.exe bot.php bot.conf

And presto! Your bot will connect to the network and start running! make sure it has auto-op in the channel you are using it in! :)

Any bugs? Drop me a comment, i’ll try my best to help you!


If you liked this post, perhaps you'd like to buy me a coffee?

Things to consider when coding a login system

This article is really based for PHP. But can work in any language really, just some general tips.

1. Usernames and passwords should be 6 characters long, or more.

2. Don’t give any extra information on a failed login.
This I belive is one of the most important parts of making your login system, you see many websites with the "Incorrect Password", and as helpful as it is it really is a security risk, on any scripts I make myself I ALWAYS go for the old reliable "Incorrect Username / Password" and so should you, why give the crackers more information than they need?

3. Passwords in the user account table of your database must be encrypted.
MD5 them or Sha1 them, its an open debate on which you do, which is more secure etc. etc., in the end, if the cracker has access to the database your in a bad place already! But why give them all the user passwords?

4. Never use "admin" or "root" as your adminstrator username.
This is one is pretty important, usually what I do here is set up my own account as admin, then have root and admin as fake accounts that log the ip’s of people who try to log into them, you could go abit more extreem here though too and ban the IP from the website straight away when they try to login, i tend to push away from that though, log the amount of attempts and what not!

5. Create a seperate area for administrators to login.
I only ever saw this technic used when working at Absolute Events, the admin centre was actually based off the address http://www.absoluteevents.ie/password of course there was a login after that, but it does through off the casual person and makes it quiet difficult, the only way this is really useful though is if you ONLY have Admin settings inside this centre, and if the user logs into the system normally they are like a normal user.

6. Logging users last login and IP.
This is one of my favorites, when the user logs in just use the PHP time() function and store it in the database, then fetch their IP and store it in the database aswell. From there you can tell the user their last login and IP, example: You last logged in on 09/06/2007 at 3.00pm with the IP: 127.0.0.1. From there the user can easily tell if they did not log in at that time and report it to an Administrator.

7. Use the maxlength attribute in forms..
This is another handy one to consider, stops the average user shoving nasty code in there! ;)

And there you have it! A couple of basics on keeping your website secure, remember though, no script is 100% secure! I have only touched on the top of security in login systems here, Jeff Skrysak covers what I have just talked about and more, including SQL injection, something I haven’t even really put in here, which is a huge risk!


If you liked this post, perhaps you'd like to buy me a coffee?





order generic viagra
viagra sale
viagra for sale in usa
levitra cialis viagra comparison online order
viagra for sale cheapest
buy bulk cialis
buy viagra from india
online order order phentermine viagra
order cialis over the phone
best price viagra
buy cheap cialis from canadian pharmacy
buy viagra on
buy viagra in windsor ontario
online order viagra
cialis generic buy discrete
viagra sale buy
where to buy viagra online
viagra sale uk
how to buy viagra online
top viagra sale
compare price brand viagra online
viagra pills for sale without prescription
buy generic cialis viagra online
cialis store vancouver
levitra cialis viagra comparison online order
buy cialis link suggest
buy cialis and viagra
buy viagra where
where can i buy viagra in dubai
where can one buy cialis
viagra retail sale
buy viagra norway
viagra sale lowest prices
where can i buy cialis online
buy canada cialis
viagra for sale in us
buy cheap generic cialis
viagra prescription sales and services in california
buy viagra
viagra low price
order viagra online
liquid cialis for sale
order cialis
buy viagra online viagra
viagra cialis online sales
viagra for sale on the internet
cyalis levitra sales viagra
viagra or sale
order viagra on line
viagra prescription sales
herbal viagra online order
buy viagra in great britain
buy viagra pills
information viagra uk order online erectile dysfunction
want to buy viagra at cheap price
viagra sildenafil citrate for sale
order viagra without a prescription
viagra cialis buy
order cialis online with no prescription
where to buy levitra cialis viagra no prescription
viagra for sale ireland
viagra and cialis for sale
viagra pills for sale
3.98 order viagra
buy cialis with no prescription
viagra sales online australia only
order viagra discretely
buy generic viagra online
stores that sale viagra
viagra online sales
cialis online sales
order viagra bucharest
buy cialis on line
order viagra sample pack check
req order viagra
cialis sales
buy viagra online without prescription
todays sales of viagra in usa
buy viagra online cheap
buy viagra in usa
how to buy viagra
store selling cialis
viagra order online no prescription
buy cialis drug online rx
buy cialis custom hrt
buy cialis uk
order free samples of viagra online
viagra order express delivery
mexico viagra drug sales
order brand cialis lowest price
buy generic cialis
viagra for sale euro
buy cialis cheap
order cialis lowest price
order cialis soft tabs in usa
mail order viagra
viagra for sale in uk
generic viagra money order
local viagra sales
viagra best price
buy cialis viagra
viagra sales online specials
order viagra air travel
where in united kingdom can i buy viagra
viagra sale usa
viagra buy cheap cheaprx cialis generic livetra
order cialis now
herbal viagra sale
the truth about viagra online sale
where to buy levitra cialis viagra
viagra on sale
buy cheap viagra online uk
buy viagra pill online
viagra sale toronto
viagra order
buy generic viagra by the pill
buy cialis soft
buy online order viagra
real viagra for sale
how can i buy viagra
viagra mail order uk
viagra online buy
sale of viagra over the years
sale viagra
order generic viagra and other prescription drugs online
generic cialis for sale
viagra cialis levitra sales figures
order viagra without prescription
cialis levitra sales viagra
buy cheap viagra in uk
buy cialis online no prescription
where to buy viagra
want to buy viagra at cheap price
to buy viagra
order viagra prescription
buy discount viagra online
cialis pills for sale
generic viagra sales
viagra for sale at pharmacy
buy viagra now
viagra for sale on line
buy viagra online
vancouver wa viagra for sale
toseeka search for products viagra sale
cialis order
cialis buy next day
order viagra cheap
buy cheap viagra online
cialis levitra sale viagra
buy to viagra where
online medicines rx cialis viagra order
buy cheap cialis
any viagra for sale on craigs list
viagra cialis sale cheap
mexico generic viagra price
real viagra on sale
viagra blue pill for sale
low price viagra
buy viagra cialis
cialis sale
cheap cialis sale online
buy viagra online uk
buy cialis kamagra uk
cialis order from us
buy cialis no online prescription
levitra cialis viagra review online order
viagra for sale county los angeles ca
buy viagra line
lowest price generic viagra
buy online viagra
levitra cialis viagra reviews online order blindness vision
maile order cialis
cialis viagra levitra sales numbers
buy and purchase viagra online
buy viagra canada
sale on viagra
viagra drugs for sale
viagra sales inn the usa
viagra buy online
affiliate viagra sales
buy free sample of viagra
buy viagra without prescription
buy cheap cialis ipharmacy
buy viagra rx
viagra pills for sale on the internet
cialis online order
buy viagra now online
for sale viagra without perscription
order viagra online
price of viagra
amerimedrx viagra order
generic online order viagra
viagra for sale in east oakland
viagra cialis online sales
order cialis uk
buy cialis viagra
buy viagra on line
viagra where to buy in the united kingdom
no online order prescription viagra
cialis buy online
cialis for order
levitra cialis viagra reviews online order
buy cialis phentermine
buy cialis without a prescription
viagra sales online
want to buy viagra
store that sale viagra online
online medicines rx cialis viagra order
levitra cialis viagra reviews online order
order viagra pills
viagra lowest price
half price viagra
online viagra sales
no prescription viagra sale
viagra sales or free samples
buy viagra without a prescription
viagra sales
order cialis cheap
viagra foe sale
order viagra no prescripion
brisbane drug store cialis
brand name viagra for sale
pharma shop viagra order
price for viagra in nogales mexico
buy 3 cialis pills
how to order cialis
where to buy levitra cialis viagra
buy viagra in uk
buy cheap generic viagra
sale generic cialis australie
cheapest price viagra
online sale viagra
book buy cialis guest jill org site
discounted viagra for sale
viagra for sale in the uk
buy generic viagra
buy cialis online tadalafil cheap vs generic
search viagra for sale
uk viagra sales
buy brand viagra usa online pharmacy
where can i buy viagra in the uk
buy cialis without prescription
best viagra price
how to order viagra
viagra pay by money order
best price for generic viagra
viagra cheap price
how we can order viagra from india to nepal
order viagra buying viagra uk
viagra pills for sale
viagra buy cheap cialis ed generic l livetra n2
viagra price comparison
viagra sales on internet
levitra cialis viagra reviews online order blindness vision
cialis sales usa
cialis order australia
buy cialis online now
levitra link order viagra
low price viagra pills
buy online cialis
buy cialis cheap in the uk
order viagra now
where to buy viagra in accra ghana
where to buy viagra on line
mail order viagra online
cialis buy discrete
viagra online order
no prescription viagra for sale
generic cialis money order
cialis line order
buy viagra shipped overnight
buy viagra low cost
viagra discount sale
buy cialis
where can i buy cialis
viagra for sale in u.k
how order viagra
buy viagra low price
sales cialis
viagra for sale birmingham al
cialis buy without prescription
buy cialis online
order viagra over internet need no doctor
order viagra
viagra com pills for sale
pfizer viagra sales
cialis online sale
buy viagra order cheap online
order online free viagra
order cialis without prescription
cialis order no prescription
price viagra
cialis levitra sale viagra
viagra on line order
where to buy levitra cialis viagra no prescription
viagra usa no script money order
viagra order on line
cheap viagra for sale in england
overseas viagra sale
buy cialis australia
order viagra canada
buy generic cialis in australian pharmacy
best place to buy viagra
online order australia cialis
cheap viagra for sale
viagra dosage and price
viagra to buy
buy prescription viagra
order generic cialis
sale of viagra
buy viagra com
viagra money order
cialis for sale
buy viagra uk
viagra sale prices
sale uk viagra
best price on generic viagra
how to buy viagra in stores
buy viagra online without a prescription
buy cheap viagra
how to order viagra on line
buy real viagra online
pfizer lab viagra for sale
canada sale of viagra
dream order pharmaceutical viagra
viagra cialis levitra sales figures
online viagra sale
viagra order herbal
keyword order viagra
buy generic cialis online
american viagra sales
sale medicine viagra the letter
buy viagra with money order
order viagra online
viagra sale online
buy viagra low price
lowest price viagra
cheapest place to buy viagra online
buy viagra cheap
buy list site viagra
buy cheap cialis online
cheapest viagra for sale in the uk on the internet
order cheap cialis
cialis order cod
viagra price
order viagra cialis
cialis generic sale
lowest viagra price
free viagra order online
order discount viagra compare
viagra sale rx
viagra and cialis for sale
order generic viagra on line
online order viagra
buy cialis paypal
buy viagra
buy viagra in nevada
order no prescripion viagra
sale of viagra
viagra order online
buy cialis online viagra
buy cialis generic
order generic viagra fast delivery
cialis mail order
buy generic cialis with your mastercard now
buy viagra no prescription
buy cheap cialis in australia
toronto viagra sale
for sale viagra without perscription from canada
buy cialis in singapore
discount order viagra
buy cialis online viagra
viagra prescription sale
viagra for sale online
buy cheap generic cialis online
buy cialis in the uk
cheapest viagra price
buy cialis online order cheap
viagra sales in uk
search order viagra without perscription
mail online order viagra
order viagra for cheap
cialis levitra sales viagra
generic viagra sales phone number ordering
buy cialis tablets
four free viagra with order
viagra best buy
order viagra cialis
generic cialis sale
europe online sale viagra
viagra online sale
buy viagra alternative
viagra pill for sale
quality mail order viagra
viagra by mail order
buy generic cialis in brisbane
best price for viagra
viagra for sale will buy
online order cialis
order cialis online
to buy cialis
generic viagra buy on line
cialis on sale
buy viagra porno
viagra order by phone
cheap viagra order online
where can i buy viagra
canada mail order pharmacy viagra levtra
cialis store drugstore
buy viagra in the uk
buy viagra c.o.d
order viagra consultation
levitra cialis viagra review online order
levitra cialis viagra review order
viagra order no prescription
3.99 cialis order
viagra discount sales
order cheap viagra
cialis potency when store in heat
buy cialis generic online