Monday, March 31, 2014

SMARTY BASIC CONCEPT

-----
SMARTY BASIC CONCEPT

INTRODUCTION

STEPS

WITHOUT SMARTY

1) Create Directory Structure.

2) Edit Codes.

2.1) index.php
<HTML>
<HEAD>
<TITLE>User Registration using Smarty application</TITLE>
<style type="text/css">
body{
font-family:Arial, Helvetica, sans-serif;
font-size:12px;
color:#333333;
}
</style>
</HEAD>
<BODY >
<form method="post" action="register.php">      
<div>
<div>Name : <input type="text" name="fullname" id="fullname"></div>
<div>User Name : <input type="text" name="user_name" id="user_name"></div>
<div>Password : <input type="text" name="password" id="password"></div>
<div><input type="submit" name="submit" value="submit" ></div>
</div>
</form>
</BODY>
</HTML>
2.2) register.php
<?php
include("config.php");
if(isset($_POST))
{
$query = "INSERT INTO USERS(fullname,user_name,password)   VALUES (' ".mysql_escape_string($_POST['fullname'])."', '".mysql_escape_string($_POST['user_name'])."','".md5($_POST['password'])."')";
$result =  mysql_query($query);
if($result)
{
echo "<script>window.location='index.php?msg=successfully inserted ';</script>";
}
}
?>
2.3) config.php
<?php
$dbHost = "localhost";
$dbUser = "root";
$dbPassword="root";
$dbName="smarter1";
$con = mysql_connect($dbHost,$dbUser,$dbPassword);
$sel = mysql_select_db($dbName,$con) or mysql_error();
?>

3) Prepare Database

3.1) Create a new database “smarter1”.
CREATE DATABASE `smarter1`;


3.2) Create table “users”.
CREATE TABLE USERS (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
fullname VARCHAR( 255 ) NOT NULL ,
user_name VARCHAR( 255 ) NOT NULL ,
password VARCHAR( 255 ) NOT NULL ,
created_on TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
NOT NULL DEFAULT CURRENT_TIMESTAMP
);

4) Test Website.

WITH SMARTY

Download Smart Package from http://www.smarty.net/download and extract into webroot as smarter2.

1) Directory Structure

Add the following files:
But the content will slightly differ from the previous steps.

2) Edit Codes.

2.1) index.php (different from previous codes)
<?php
include("libs/Smarty.class.php");
include("config.php");
$smarty = new Smarty;
$smarty->debugging = true;
$smarty->caching = true;
$smarty->cache_lifetime = 120;
$smarty->assign("title", "User Registration using Smarty application");
$smarty->display('index.tpl');
?>
2.2) register.php (same as previous codes)
<?php
include("config.php");
if(isset($_POST))
{
$query = "INSERT INTO USERS(fullname,user_name,password)   VALUES (' ".mysql_escape_string($_POST['fullname'])."', '".mysql_escape_string($_POST['user_name'])."','".md5($_POST['password'])."')";
$result =  mysql_query($query);
if($result)
{
echo "<script>window.location='index.php?msg=successfully inserted ';</script>";
}
}
?>
2.3) config.php (same as previous codes)
<?php
$dbHost = "localhost";
$dbUser = "root";
$dbPassword="root";
$dbName="smarter1";
$con = mysql_connect($dbHost,$dbUser,$dbPassword);
$sel = mysql_select_db($dbName,$con) or mysql_error();
?>
Add new template files in smarter2/templates/…
2.4) header.tpl
<HTML>
<HEAD>
<TITLE>{$title}</TITLE>
{literal}
<style type="text/css">
body{
font-family:Arial, Helvetica, sans-serif;
font-size:12px;
color:#333333;
}
</style>
{/literal}
</HEAD>
<BODY >
2.5) index.tpl
{include file="header.tpl" title={$title}}  
<form method="post" action="register.php">      
<div>
<div>Name : <input type="text" name="fullname" id="fullname"></div>
<div>User Name : <input type="text" name="user_name" id="user_name"></div>
<div>Password : <input type="text" name="password" id="password"></div>
<div><input type="submit" name="submit" value="submit" ></div>
</div>
</form>
{include file="footer.tpl"}
2.6) footer.tpl
</BODY>
</HTML>

3) Prepare Database

3.1) Create a new database “smarter2”.
CREATE DATABASE `smarter2`;


3.2) Create table “users”.
CREATE TABLE USERS (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
fullname VARCHAR( 255 ) NOT NULL ,
user_name VARCHAR( 255 ) NOT NULL ,
password VARCHAR( 255 ) NOT NULL ,
created_on TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
NOT NULL DEFAULT CURRENT_TIMESTAMP
);

4) Test Website.

PHP FRONT CONTROLLER BASIC CONCEPT

-----
FRONT CONTROLLER BASIC CONCEPT

STEPS

1) Create Directory Structure.

[webroot]\frontcontroller1\
----------index.php
----------pages\
--------------------home.php
--------------------account.php

2) Codes

2.1) index.php

<?php
  session_start();
  $redirect = !empty($_GET["page"])? $_GET["page"] : "home";
  switch($redirect){
   case "home":
      include "pages/home.php";
      break;
   case "account":
      include "pages/account.php";
      break;    
  }
?>
2.2) home.php

<?php
echo "this is home";
?>
2.3) account.php

<?php
echo "this is account";
?>

Sunday, March 30, 2014

PHP Configuration For PHP Website Development


-----
PHP Configuration For PHP Website Development

INTRODUCTION

The configuration file (php.ini) is read when PHP starts up. For the server module versions of PHP, this happens only once when the web server is started. For the CGI and CLI versions, it happens on every invocation.

STEPS

1) FINDING PHP CONFIG FILE.

Click the Source File button besides the PHP Config button in the Configuration Section of UwAmp.

2) EDITING PHP CONFIG FILE.

(If you have configured UwAmp to use Notepad++ to edit the text file, )  Notepad++ shows the content of PHP Config file ie, php.ini
Note: The location shown by the Notepad++ title bar is C:\UwAmp\bin\php\php-5.3.25\php_uwamp.ini. This path may differ subject to the location where UwAmp is stored.

3) GUI Approach To Learn PHP Extensions and Settings.

 UwAmp provides a friendlier interface for you to look at the settings and learn to use them.
3.1) PHP Extensions.
3.2) PHP Settings.

4) Using PHPSecInfo Script to check PHP Configurations.

PhpSecInfo provides an equivalent to the phpinfo() function that reports security information about the PHP environment, and offers suggestions for improvement. It is not a replacement for secure development techniques, and does not do any kind of code or app auditing, but can be a useful tool in a multilayered security approach.
4.1) Download the phpsecinfo.zip here.
4.2) Extract the folder phpsecinfo-20070406, copy it into www folder and rename as “phpsecinfo”.
4.4) Click on More Information link to learn more on the issues mentioned.

FURTHER EXERCISE

Run phpsecinfo on your XAMPP site and compare the results.

HTTPD Configuration For PHP Website Development


-----
HTTPD Configuration For PHP Website Development

INTRODUCTION

Apache HTTP Server is configured by placing directives in plain text configuration files. The main configuration file is usually called httpd.conf. The location of this file is set at compile-time, but may be overridden with the -f command line flag. In addition, other configuration files may be added using the Include directive, and wildcards can be used to include many configuration files. Any directive may be placed in any of these configuration files. Changes to the main configuration files are only recognized by httpd when it is started or restarted.

PREPARATION

This tutorial uses UwAmp server package.
Set the Text Editor value as the path pointing to Notepad++ program.

STEPS

1) FINDING HTTPD CONFIG FILE.

Click the Source File button besides the Apache Config button in the Configuration Section of UwAmp.

2) EDITING HTTPD CONFIG FILE.

(If you have configured UwAmp to use Notepad++ to edit the text file, )  Notepad++ shows the content of Apache Config file ie, httpd.conf
Note: The location shown by the Notepad++ title bar is C:\UwAmp\bin\apache\conf\httpd_uwamp.conf. This path may differ subject to the location where UwAmp is stored.

3) SYNTAX.

httpd configuration files contain one directive per line. The backslash "\" may be used as the last character on a line to indicate that the directive continues onto the next line. There must be no other characters or white space between the backslash and the end of the line.
Arguments to directives are separated by whitespace. If an argument contains spaces, you must enclose that argument in quotes.
Directives in the configuration files are case-insensitive, but arguments to directives are often case sensitive. Lines that begin with the hash character "#" are considered comments, and are ignored. Comments may not be included on a line after a configuration directive. Blank lines and white space occurring before a directive are ignored, so you may indent directives for clarity.

4) MODULES.

httpd is a modular server. This implies that only the most basic functionality is included in the core server. Extended features are available through modules which can be loaded into httpd. By default, a base set of modules is included in the server at compile-time. If the server is compiled to use dynamically loaded modules, then modules can be compiled separately and added at any time using the LoadModule directive. Otherwise, httpd must be recompiled to add or remove modules. Configuration directives may be included conditional on a presence of a particular module by enclosing them in an <IfModule> block. However, <IfModule> blocks are not required, and in some cases may mask the fact that you're missing an important module.

5) SCOPE OF DIRECTIVES.

Directives placed in the main configuration files apply to the entire server. If you wish to change the configuration for only a part of the server, you can scope your directives by placing them in <Directory>, <DirectoryMatch>, <Files>, <FilesMatch>, <Location>, and <LocationMatch> sections. These sections limit the application of the directives which they enclose to particular filesystem locations or URLs. They can also be nested, allowing for very fine grained configuration.
httpd has the capability to serve many different websites simultaneously. This is called Virtual Hosting. Directives can also be scoped by placing them inside <VirtualHost> sections, so that they will only apply to requests for a particular website.

6) PHP Configuration.

6a) Registering PHP interpreter.
6b) Registering valid file extension for PHP Interpreter to execute.

7) UWAMP ADDITIONAL SETTINGS

Filename: C:\UwAmp\UwAmp README

_   _           ___                  
| | | |         / _ \                
| | | |_      _/ /_\ \_ __ ___  _ __  
| | | \ \ /\ / /  _  | '_ ` _ \| '_ \
| |_| |\ V  V /| | | | | | | | | |_) |
 \___/  \_/\_/ \_| |_/_| |_| |_| .__/
                               | |    
                               |_|    
01010101 01110111 01000001 01101101 01110000
V 2.2.1                www.uwamp.com
--------------------------------------------
Apache config file :
        UwAmp\bin\apache\conf\httpd_uwamp.conf
PHP config file :
        UwAmp\bin\php\CURRENT PHP VERSION\php_uwamp.ini
                
MYSQL config file :
        UwAmp\bin\database\mysql\my_uwamp.ini
MYSQL PASSWORD :
        user : root
        password : root
Available Macro in setting:
        {TEMPPATH}                        = UwAmp\temp
        {APACHEPATH}                         = UwAmp\bin\apache
        {DOCUMENTPATH}                         = UwAmp\www
        {PHPAPPS}                        = UwAMp\phpapps
        {PHPPATH}                         = UwAmp\bin\php\CURRENT PHP IN UWAMP CONTROL\
        {PHPAPACHE2FILE}                 = UwAmp\bin\php\CURRENT PHP IN UWAMP CONTROL\CURRENT apache2.dll
        {PHPEXTPATH}                         = UwAmp\bin\php\CURRENT PHP IN UWAMP CONTROL\ext
        {PHPZENDPATH}                         = UwAmp\bin\php\CURRENT PHP IN UWAMP CONTROL\zend_ext
        {PHPMODULENAME}                        = Module name of current php version
        {LISTEN_VIRTUAL_HOST_PORT}        = Apache Listens ports
        {MYSQLPATH}                        = UwAmp\bin\database\mysql\
        {MYSQLBINPATH}                        = UwAmp\bin\database\mysql\bin
        {MYSQLDATAPATH}                        = UwAmp\bin\database\mysql\data
        {ONLINE_MODE}                        = Order allow,deny
                                          Allow from all
                        OR
                                        = Order deny,allow
                                          Allow from 127.0.0.1 localhost
        if ONLINE_MODE is set to Online the serveur is available for all IP
        if ONLINE_MODE is set to Offline the serveur is available just for 127.0.0.1

8) FURTHER EXERCISE

Check the httpd file for XAMPP for the above items.
8.1) httpd.conf
8.2) httpd-xampp.conf

Labels