The same file (counter.txt) is used for both reading as well as writing. So each time the file should be closed before opening for the next time as read or write mode.
<?php $filename=”counter.txt”; $f=fopen($filename,”r”) or die(”Read Failed”); $str=fread($f,filesize($filename)); echo “The page has been visited [...]
Continue reading Hit Counter using PHP files
This scripts tells how to submit a form to the same page itself….
<form method=post action=”<?php echo $_SERVER['PHP_SELF']; ?>”> Enter your Name: <input type=text name=user> <input type=submit name=submit> </form> <?php if(isset($_POST['submit'])) { $user=$_POST['user']; [...]
Continue reading Submitting the html form to the same page
For uploading Files to the server, we need to run two files, For example let us say upload.html (to select the file) and upload.php (to upload)…. let us define each of the two files
//upload.html
<form method=post action=upload.php enctype=multipart/form-data> Select a File: <input type=file name=myfile> <input type=submit value=upload> </form>
//upload.php
<?php [...]
Continue reading File Upload to Server in PHP
There are different sorting functions used to sort the arrays and other variables. Some of the their functions are listed below:
sort() – used to sort an array in normal order
rsort() – used to sort an array in normal reverse order
asort() – used to sort array and maintain the index association(key value pair maintains even after [...]
Continue reading Sorting Functions in PHP
The following script tries to connect the database and if it is failed it will display relevant message. The server is localhost and username/password combination is root/abc123. it is necessary to create a database ‘dummy’ before executing the script. Click here to set password for mysql and phpmyadmin
<?php
$con=mysql_connect(”localhost”,”root”,”abc123″) or die(”Couldnt Connect to database”);
$a=mysql_select_db(”dummy”,$con);
if($a)
echo “Database Selection [...]
Continue reading Connect to MySQL Database using PHP
If a user visits a website, where he is asked for validating his username and password and will be validated with the MySQL Database. the following scripts demonstrate this.Step 1: create a database called dummy by executing “create database dummy” in mysql command window or shell windowStep 2: Create a table called usertable with two [...]
Continue reading User Validation/Authentication in PHP
How to send email using PHP. The following section describes that with coding…..
Before using Mail in PHP, note that, PHP mail is intended for only a small scale use and not for large scale Email systems. So for large scale, you may use other mal softwares.
Email can be sent
as ordinary plain message
as an HTML [...]
Continue reading Sending Email in PHP
Username/password Creation in PHP and MySQL. a Simple form is designed to get the username and two passwords the objectives are
1. Both the username and password should contain atleast 6 characters
2. both the passwords should be same
3. upon submitting to the database, the existence of username is checked with the database, if the username already [...]
Continue reading User Creation using PHP/MySQL
To Set cookies using PHP, setcookie() function is used. Cookie is a piece of information that stored in the client’s machine (usually browser) by the server.
setcookie() contains 6 parameters
Name of the cookie- usage- “FirstCookie”
The value of the cookie. This value is stored on the clients computer; do not store sensitive information. Assuming the name [...]
Continue reading How to Set Cookies in PHP
Source : http://www.openpeta.com
<?php /* * FileName:validation.php * Created on Jan 16, 2007 * Author:Antony */ function validateUname($uname) { if (ereg(’^[a-zA-Z0-9_]{3,50}$’, $uname)) return true; else [...]
Continue reading Input Validators in PHP