PHP script to get the user or client IP address

To get the client IP address <?php $strCurrentTime = date(“y-m-d h:i:s”,time()); $strIP = $_SERVER[‘REMOTE_ADDR’]; echo $strIP; ?> output 127.0.0.1 Note: IP address is dynamic so output may differ.

Categories PHP

PHP script for sample contact page for website

Contact page for website <?php include(‘config.inc.php’); class ContactUs { var $arrErrors = array(); var $strSuccess = ”; public $strSelect=null; public $objResult=null; var $objConfig = null; var $objDbConn=null; var $intRandSiteLimit = 35; var $arrRandSites = array(); var $strName = ”; var $strPhone = null; var $strEmail = ”; var $strContent = ”; var $strReferrer = null; … Read more

Categories PHP

How to create user login, forgot password and logout page using php script

To create a login page in php Note: Create a table tbl_login with uname and pwd //config.inc.php <?php class Config { public $dbHostname = ‘localhost’; public $dbUsername = ‘root’; public $dbPassword = ‘xxx’; public $dbName = ‘dbname’; } ?> //index.php <?php session_start(); include(“config.inc.php”); class Login { public $strUsername = null; private $strPassword = null; public $arrErrors … Read more

Categories PHP

Simple PHP script for practice to learners and students

To print a string using php <?php echo “Welcome to learn PHP”; print “Enjoy it”; ?> output Welcome to learn PHP Enjoy it Note: Using echo and print, you can display the string in php To display a number from 1 t0 5  in for loop <?php for($i=1; i<=5; $i++) { echo $i; echo “<br/>”; } … Read more

Categories PHP

How to output or print the array results in php

To print an array result using var_dump() <?php $a = array(1, 2, array(“a”, “b”, “c”)); var_dump($a); ?> Note: var_dump() is used to dumb the information about the variable output array 0 => int 1 1 => int 2 2 => array 0 => string ‘a’ (length=1) 1 => string ‘b’ (length=1) 2 => string ‘c’ (length=1) To print an array result … Read more

Php script or program to find square root of a given number

Simple program to find square root of a given number <?php $num=9; $root=0; $odd=1; while($num>0) { $num-=$odd; $root++; $odd+=2; } echo $root; ?> output  3 Program to find square root of a given number using sqrt functions, classes and objects <?php class square { public $num=null; public $objRes=null; function processRequest() { $this->square=$_REQUEST[‘num’]; } function run() … Read more

Categories PHP

PHP script to find the odd or even numbers

Here, we find simple php script to find the given number is odd or even. These are the basic programs used during PHP training for students. Simple program to find odd or even number <?php $num=$_REQUEST[‘num’]; if($num%2==0) { echo “Even number”; } else { echo “odd number”; } ?> <html> <body> <form action=”even.php” method=”post”> Enter … Read more

Categories PHP

How to install, setup and configure Wamp server

wamp

WAMP

WAMP is an acronym, where W stands for Windows, A stands for Apache, M stands for MYSQL,  P stands for PHP, which refers to set of open source application combined with microsoft windows, which are commonly used for web server environment.

Step 1:Installation

First have to download the latest version of WAMP server from http://www.wampserver.com/en/download.php . You will have the options to choose either 32-bit or 62-bit version your choice is based on your system configuration. After completion of downloading, extract the folder and run the .exe file.

 

wamp1

Click Next button, you will be asked to accept the license agreement. Accept it and go ahead.

Step 2: Specify a folder

Next step is to select where you would like to install a WAMP server. Default will be C:/wamp. If you want to install in some other directory is also possible.

wamp2

Step 3: Additional Task

After choosing the directory, it will provide the option to set up  icons.Select from the options whatever you need.

wamp3

Once completed click Next button and confirm the installation settings by clicking Install button.

Once the installation finish installing its files WAMP detects which is your default browser at that moment. Click No and choose any other browser you want. If your firewall pops up make sure to grant Apache access.

Step 4: PHP Mail Parameters

If you would like to have a mail parameters,  just you have to configure the SMPT server by clicking Next button.

wamp4

WAMP installed successfully message is displayed. Now you have to test the wamp server by starting it. Once the WAMP is started the small W icon is available in toolbar.

Note: If the  W icon is in red color means everything is stopped. If it is in green color means everything is running and if it is in orange color means some services are running.

Step 5: Check the installation

Now its time to check whether everything is installed correctly. Type localhost in browser, if you seen the following screen in your browser, then everything is working fine. Just you have to modify some files to access WAMP via the http:// localhost link.

wamp5

Open a WAMP management console highlight Apache and then click httpd.conf .Open in text editor and find the line ‘Allow from 127.0.0.1’ and add ‘Allow from ::1’ below it now. Then save the file and restart the server,then open localhost in browser.If you see the following screen in browser then everything is right.

wamp6

 

Note: If you want to provide password for your server, go to phpmyadmin in your folder and open config.inc.php file for editing and provide password.

Read more