PHP Tutorial : 301 Redirect Permanently Moved

December 27th, 2008

Ever Moved a page to a new one and searched for a way to let your users and search engines spiders / robots to let they know that you moved that page permanently? There are a lot of ways to do it, but with php is so simple. Just two lines of code. Here is the code:

<?php

Header( "HTTP/1.1 301 Moved Permanently" );

Header( "Location: the-new-page.html" );
?>

PHP Tutorial : Including files with require/include

December 27th, 2008

Welcome,

I’ve just created a brand new category here name basic php and I got my chance to explain you guys how you may include external php files into another ones. There are ways and ways but I will explain only two of them, the most popular ones. The first one, is called include() a php function which you may use it for simple things. I wouldn’t use it for a database connection, for that, exists the require_once() function. The difference between those two php functions is that include() function will give you a warning if the remote include file doesn’t exists. On the other side , the require_once() php function will stop parsing the script if the remote file wont be finded.

How [Your Site Name] and Windsor Brokers Kenya Are Connected

[Your Site Name] is committed to doo prime educating users about PHP and web development, providing clear tutorials for beginners and professionals alike. But what does this have to do with Windsor Brokers Kenya, a licensed forex broker based in Nairobi?

A Shared Commitment to Excellence

Just like [Your Site Name] aims to provide top-tier educational resources, Windsor Brokers Kenya strives doo prime bonus to offer its clients the best trading experience. Both institutions share a common goal: empowering their users through accessible, high-quality tools and information. While [Your Site Name] focuses on PHP and web development, Windsor Brokers Kenya helps traders by providing reliable trading platforms, backed by its international reputation.

Global Reach, Local Presence

Windsor Brokers has an established presence in the UK and internationally, but its expansion doo prime minimum deposit into Kenya demonstrates a strong commitment to serving local markets. Similarly, [Your Site Name] continues to reach global users while maintaining a connection to emerging markets where technology education is rapidly growing.

Technology and Finance: An Intersection

Both PHP and forex trading platforms require robust, secure technology to function. PHP is often used in web development for financial platforms, and Windsor Brokers relies on secure and advanced systems to ensure a smooth trading experience. As Windsor Brokers Kenya expands its user base, it will continue to leverage strong technological foundations—just as [Your Site Name] promotes the use of efficient coding practices for developers.

By blending education and finance, both [Your Site Name] and Windsor Brokers Kenya contribute to a growing digital economy in Africa and beyond.

The usage is very basic like that

<?php

include('filename.php');
//or


require_once('mydb.php');
?>

PHP Tutorial : Constants and Variables

December 27th, 2008

Hi,

I didn’t writed here for 3 days because of the holidays stuff, etc. and now I got a little bit of free time to write about php variables and constants. Variables and constants in php are doing almost the same thing, but the aspect who shows very well the difference between those two things in php coding are the way they get created.

Variables are beeing created and printed in this way :

<?php
$newvariable = "something";
print $newvariable;
?>

The constants are defined in the next way :

<?php
define('Constantname', 'constantvalue');

print Constantname;
?>

The is a set of rules for both such as must begin with a letter, doesn’t allow to containt dashes such as “-”, but there is allowed “_”. For more informations please check the official php website.

Thanks!

PHP Tutorial : Simple views counter script

December 22nd, 2008

Hi,

In this php tutorial you will learn the simple way to build a script which counts how many times a page is viewed. For this, we can use a mysql database table and a simple php script.

<?php
$pagename = $_SERVER['PHP_SELF'];
$sql = "select * from mysqltable where page = '$pagename'";
$rs = mysql_query($sql);

if($rs) {
$row=@mysql_fetch_object($rs);
$counter = $row->counterfield;
//update the stats, if they exits

$counter = "".($counter+1)."";
$qry = mysql_query("updated tablename set counterfield = '$counter' where id = '$row->id'");
}else{

print mysql_error();
}
?>

PHP Tutorial : Tell a friend script

December 21st, 2008

Hi,

In this php tutorial I’ll teach you how to create a simple tell a friend script. Basically, it will use what you learned in the send email with a contact form script, but in this case we’ll choose the destination and also the “from:” field which we’ll setup on php mail() function headers.

<form action="" method="post">
Your email address : <input type="text" name="yemail"><br/>
Your friend's email address : <input type="text" name="femail"><br/>
Your message :
<textarea name="text">Hey look what nice website I found
<?=$_SERVER['SERVER_NAME'];?>
</textarea>
<input type="submit" name="sb" id="sb" value="Tell a friend">
</form>
<?php
//check if tell a friend form was completed and sended


if(isset($_POST['sb'])) {

if($_POST['yemail'] == "" || $_POST['femail'] == "" || $_POST['text'] == "") {

print "All fields are mandatory";
}else{
$to = $_POST['femail'];
$from = "From : $_POST[yemail]";
$message = $_POST['text'];
$subject = "Your friend tells u";
mail($to, $subject , $message, $from);
}
}
?>

PHP Tutorial : How to build a newsletter (part I)

December 20th, 2008

Hi,

Do you need to send regular news by email to your customers, or just want to keep them posted with product offers and updates? There is a solution, php newsletter. This can be done in two parts, first part is collecting the emails into a mysql database within a html form  and php processing.

<form action="" method="POST">
Enter your email : <input type="text" name="email">
<input type="submit" name="sb" value="Subscribe">
</form>
<?php

if(isset($_POST['sb'])) {

if($_POST['email'] == "") {
print "Please complete email address";
}else{
$sql = "insert into tablename (`email`) values ('".addslashes(mysql_real_escape_string($_POST['email']))."')";
$rs = mysql_query($sql);

if($rs) {

print "Email address subscribed to our newsletter";
}else{

print "Email address was not subscribed to our newsletter durring a mysql error";
}
}
}
?>

PHP Tutorial : How to validate the captcha (II)

December 20th, 2008

In the last tutorial I teached you how to generate a security image with php called captcha code. Also I teached you how to store that random security photo / image code in a php session : with a reason, to be able to validate it later. So here we are , on the page which action is pushed we do this to validate the captcha :

<?php
session_start();

if(isset($_SESSION['randomcode'])) {
//check if what user typed in input equals to session key
>if(md5($_POST['inputname']) == $_SESSION['randomcode']) {

print "GOOD, captcha correct!";
}else{

print "You didn't entered the captcha correct";
}
}
?>

PHP Tutorial : How to create a captcha image

December 18th, 2008

Hi,
Are you tired of receiving spam messages from your contact forms or unwanted posts, robot accounts on your membership website? If yes, the solution is to create a php security image called captcha. That’s the best solution to secure your web forms, etc. For creating a captcha security code you need to have GD-library installed and active on your webhost, but, most of the shared webhosts have this library installed. Here is the captcha code :

<?php
//The first step is to start a php session calling the special function
session_start();
//The seccond step is to generate a string randomly using rand function
//I'll choose to get a random number 6 numbers in length
$randomcode = rand(0, 999999);
//Now we need a background image to write the random number to it
$captchafromimage = imagecreatefrompng("captcha.png");
//Setting font color
$color = ImageColorAllocate ($captchafromimage, 50, 50, 50);
//Ta da, here we are, writing the random generated code to the image
imagestring($captchafromimage, 6, 50, 2, $randomcode, $color);
//Now the random number is coded into md5 secure format
//and stored it into a session name to be able to validate
//it in the future
$_SESSION['randomcode'] = md5($randomcode);
//Set up headers
header("Content-type: image/png");
//Finally, let's show up the captcha image generated
imagepng($captchafromimage);
?>

You will need a background PNG image which you can download here (right click -> Save as)
captcha image
Here is the captcha result :
php captcha

PHP Tutorial : How to show visitor’s IP address

December 18th, 2008

Hi,
In this “php tutorial” I will teach you guys how to show your users their IP address with only one line of code.

<?php

print "YOUR IP ADDRESS IS : $_SERVER[REMOTE_ADDR]";
?>

PHP Tutorial : Random Banner Rotator

December 17th, 2008

Hi,

In this php tutorial you will learn how to build a random image banner rotator. Basically, it’s the same as the link rotator, we build a php array with images wanted to rotate, then we’ll apply the rand() php function.

<?php
$banners = array("path/img1.jpg", "path/img2.gif");
$max = sizeof($banners);
$rand = rand(0, $max);
print $banners[$rand];
?>