Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Sunday, May 1, 2011

What is Apache Web Server?

Often referred to as simply Apache, a public-domain open source Web server developed by a loosely-knit group of programmers. The first version of Apache, based on the NCSA httpd Web server, was developed in 1995.

Core development of the Apache Web server is performed by a group of about 20 volunteer programmers, called the Apache Group. However, because the source code is freely available, anyone can adapt the server for specific needs, and there is a large public library of Apache add-ons. In many respects, development of Apache is similar to development of the Linux operating system.

The original version of Apache was written for UNIX, but there are now versions that run under OS/2, Windows and other platforms.

The name is a tribute to the Native American Apache Indian tribe, a tribe well known for its endurance and skill in warfare. A common misunderstanding is that it was called Apache because it was developed from existing NCSA code plus various patches, hence the name a patchy server, or Apache server.

Friday, April 8, 2011

WEEK 12 - PHP

Buka xampp untuk Start MySQL

pilih SCM (window Services akan terbuka) dan stop kan IIS

C:\xampp\htdocs\learning
C:\xampp\mysql\data\data

Cuba tengok di bahagian Application dalam Dreamweaver
dah ada dmx

Cuba http://localhost/ di Firefox untuk ke xampp

Friday, April 1, 2011

PHP GUESTBOOK TUTORIAL

First off we need phpMyAdmin and to create admin table and insert some admins inside it, here is code you need for phpMyAdmin, use same database as your guestbook is in.

CREATE TABLE admins (
username varchar(50),
password varchar(50),
id int(11) NOT NULL auto_increment,
PRIMARY KEY (id)
) TYPE=MyISAM;

Now over phpMyAdmin you need to add admins, go to admins table and click insert, write in username and password, from scroll down box on left from password select MD5 so it protects it with md5 hash, when you have done that it’s start to do admin part of guestbook, make folder admin where your guestbook is and inside it make first file named form.php, put this code inside.














Username:
Password:


When you have made form we need login.php file that will check for login details and if successful it will log you in.

// Check if login button has been pressed
if(isset($_POST['login'])){
// Define username and password
$username = $_POST['username'];
$password = $_POST['password'];
// Do some stripslashes on them
$username = stripslashes($username);
$password = stripslashes($password);
$password = md5($password);
// Include our config file for mysql server connect and select database
include "../config.php";
// Query admins table and check if admin data is good
$query = "SELECT username, password FROM admins WHERE username = '$username' AND password = '$password' LIMIT 1";
$result = mysql_query($query);
$count = mysql_num_rows($result);
// If result is good start session and register it with s_logged_n
if($count == 1){
session_start();
$_SESSION['s_logged_n'] = 'true';
$_SESSION['s_username'] = $username;
// Display successful login message
echo "You have sucessfully logged in, click here to access admin area";
} else {
// If user or pass is wrong display it
echo "Invalid username or password";
}
} else {
// If someone try to open login.php only tells them to use form
echo "You must login over form, click here to go back to login";
}
?>

Now when we have login.php we need index.php where our post from guestbook and options to edit or delete them will be, so make file index.php and put this code inside

// Start sessions and check if sessions is registered from login form, if it is true display admin data, else display that you must login
session_start();
if(
$_SESSION['s_logged_n'] == 'true'){
?>
Welcome to admin area echo $_SESSION['s_username']; ?>, here you can administrate guestbook.




= "10";
// Include config file
include "../config.php";
// if we don't get page number get page number 1
if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}
// Max results per page
$max_results = "$max";
$from = (($page * $max_results) - $max_results);
// Do query on database table
$query = "SELECT * FROM guestbook ORDER BY id DESC LIMIT $from, $max_results";
$result = mysql_query($query);
// If query is ok then output messages from guestbook
if ($result) {
while (
$row = mysql_fetch_array($result)):
?>










endwhile ?>


Posted by echo $row['name']; ?> if($row['website'] == ''){
echo
"";
} else {
echo
". $row['website'] . "\">www";
}
?>
on echo $row['date']; ?> - echo $row['id']; ?>">click to edit - echo $row['id']; ?>">click to delete
echo $row['message']; ?>

Go to page #:= mysql_result(mysql_query("SELECT COUNT(*) as Num FROM guestbook"),0);
$total_pages = ceil($total_results / $max_results);
for(
$i = 1; $i <= $total_pages; $i++){
if((
$page) == $i){
echo
"$i ";
} else {
echo
".$_SERVER['PHP_SELF']."?page=$i\" title=\"Go to page $i\">$i ";
}
}
?>

// If query fails then output it
} else {
echo
"Unable to select data from database table";
}
?>
} else {
echo
"You must login to access admin area";
}
?>

When index.php is done we need file edit.php and this code that goes in

// Start sessions and check if sessions is registered from login form, if it is true display admin data, else display that you must login
session_start();
if(
$_SESSION['s_logged_n'] == 'true'){
?>
// Get the id of the post
if(isset($_GET['id'])){
$id = $_GET['id'];
include
"../config.php";
$query = "SELECT * FROM guestbook WHERE id = '$id' LIMIT 1";
$result = mysql_query($query);
if (!
$result){
echo
"Please select what post to edit over index page";
} else {
while (
$row = mysql_fetch_array($result)):
?>

echo "$id"; ?>" method="post">





















Name:
echo $row['name']; ?>">
Email:
echo $row['email']; ?>">
Website:
echo $row['website']; ?>">
Message:



endwhile ?>
}
}
} else {
echo
"Please login over
form."
;
}
?>

And now our delete.php file that has this code

// Start sessions and check if sessions is registered from login form, if it is true display admin data, else display that you must login
session_start();
if(
$_SESSION['s_logged_n'] == 'true'){
?>
// Get the id of the post
if(isset($_GET['id'])){
$id = $_GET['id'];
include
"../config.php";
$query = "DELETE FROM guestbook WHERE id = '$id' LIMIT 1";
$result = mysql_query($query);
if (
$result){
echo
"Successfully deleted post";
} else {
echo
"There was an error deleting post";
}
}
} else {
echo
"Please login over form.";
}
?>

And now finally our update.php file that have contents of updating posts inside, code goes like this

// Start sessions and check if sessions is registered from login form, if it is true display admin data, else display that you must login
session_start();
if(
$_SESSION['s_logged_n'] == 'true'){
?>
// If form button has been pressed then do the following
if(isset($_POST['update'])){
// Get id of post
$id = $_GET['id'];
// Include config file
include "../config.php";
$name = $_POST['name'];
$email = $_POST['email'];
$website = $_POST['website'];
$message = $_POST['message'];
// Make some preg replaces
$name = preg_replace("/>/",">",$name);
$name = preg_replace("/,"<",$name);
$email = preg_replace("/>/",">",$email);
$email = preg_replace("/,"<",$email);
$website = preg_replace("/>/",">",$website);
$website = preg_replace("/,"<",$website);
$message = preg_replace("/>/",">",$message);
$message = preg_replace("/,"<",$message);
// Add few stripslashes...
$name = stripslashes($name);
$email = stripslashes($email);
$website = stripslashes($website);
$message = stripslashes($message);
// Check if fields name, email and message are empty
if ((( empty($name) ) || ( empty($email) ) || ( empty($message) ))){
// If they are empty then output message
echo "Please write in all fields, name, email and message";
// Else if they are filled in check if email is valid
} elseif ((!strstr($email , "@")) || (!strstr($email , "."))) {
// If email is invalid then output it
echo "Please use valid email address";
} else {
// If all fields and email is valid then update data to database
// Do the query
$query = "UPDATE guestbook SET name = '$name', email = '$email', website = '$website', message = '$message' WHERE id = '$id' LIMIT 1";
$result = mysql_query($query);
if (
$result){
echo
"Successfully edited post";
} else {
echo
"There was error editing post";
}
}
}
} else {
echo
"Please login over form.";
}
?>

And that would be it, all this files must be inside guestbook/admin folder

Friday, March 4, 2011

ASP versus PHP 4 MAC 2011

ASP = Actives Server Pages, PHP Hypertext Preprocessor

ASP and PHP are both programming languages that are commonly used to create websites. Unlike the usual static html web pages, ASP and PHP websites are more dynamic and can allow users to interact and exchange information using the website's databases.

ASP is the short term for Active Server Pages, a type of program that works with Microsoft alongside IIS or Internet Information Server. ASP needs a Microsoft Server for the website to work. On the other, PHP or Hypertext Preprocessor, runs using Linux or Unix server. The more updated PHP programs can now run on an NT server.

Platfrom
PHP programs can also run in Windows, Solaris, Unix and Linux while ASP can only work with Window-based platforms. Just recently, ASP can now run on a Linux platform given that there is an ASP-Apache program installed on its server.

Language Programme
If you were a programmer adept with the C++ language, you would probably be more comfortable using PHP than ASP. PHP uses C/C++ as base language and most syntax are similar to each other. Because a big chunk of programmers are still using C++ language, PHP are by far more popular than ASP.


ASP is very much similar to the syntax and interface of Visual Basic programming. This is basically because Visual Basic is basically correlated with Microsoft products and programs. So if you were a programmer, choosing between ASP and PHP would basically depend on which language you are more adept with.

Server Installation Cost
When it comes to costing and expenses, ASP programs needs to run on Windows with IIS installed on the server. You need to purchase both of these components in order for ASP to work. On the other hand, a PHP would only require running on a Linux server, which you can get at no cost.

Database
PHP is very much flexible when it terms of database connectivity. It can connect to several databases of which the most commonly used is the MySQL. Note that MySQL would not cost you a thing to use. But if you were to use ASP, you need to purchase MS-SQL, which is a Microsoft product.

Speed and Secure
Loading speed is a big factor in maintaining a website. If you are particular about speed, then you need to go with PHP. PHP codes runs much quicker than ASP basically because it runs in its very own memory space while ASP uses an overhead server and is uses a COM based architecture.

Cost
In working with PHP, most tools associated with the program are mostly open source software so you need not pay for them. As for ASP, you might need to buy additional tools to work with its programs.


In conclusion, both PHP and ASP have its own advantages and disadvantages. It basically depends on which part of developing a website you are most concerned with. Are you worried about the cost of creating your website? Do you want to use a programming language that you are more familiar with? Do you want a more stable and faster website? Choosing between ASP and PHP basically depends on your own personal preference. It doesn't hurt to confer with other programmers or webmasters and research more information on which programming would best fit the requirements of your website.
ASP versus PHP

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | belt buckles