Archive

Archive for the ‘php & mysql’ Category

Creating A File Upload Script

April 28th, 2009 Ahsun Taquveem Chohan 1 comment

I will teach you how to create a basic script that allow people to upload files and stores details of their uploads in a database. Follow up, it is not hard at all…. If you have questions, feel free to ask

First we need to create the database table with the following SQL:

 

CREATE TABLE `uploads` (
`id` int(10) unsigned NOT NULL auto_increment,
`whenuploaded` datetime NOT NULL default '0000-00-00 00:00:00',
`ipaddress` varchar(15) NOT NULL default 'unknown',
`imageloc` varchar(255) NOT NULL default 'unknown',
`imagesize` int(10) unsigned default NULL,
`imagetype` varchar(30) default NULL,
PRIMARY KEY (`id`)
) TYPE=MyISAM;

 

Then here’s the PHP code you need at the top of the page where you’re going to have your upload form. You need to change the database access details at the top and the ‘defines’ to specify your domain and path names. Create the DEST_DIR directory on the server with 777 permissions.

Read more…

Login & Logout tutorial

Create a file for Login and Logout (PHP + MySQL) using with a SESSION variable. This file contains Login form, Login authorize program and Logout program. All in one but Short and Easily.

This tutorial require 2 PHP files and 1 table of mySQL database.

  1. index.php this file is the Login and Logout file.
  2. main.php this file is the target when login is O.K.
  3. Database “tutorial” and table “admin” with 3 fields: id(auto_increment), username(varchar, 50), password(varchar, 32).
    * The “password” field is design for md5() password for more sucurity.Then put a record into this table. In this tutorial, put a record with name “admin” and password “81dc9bdb52d04dc20036dbd8313ed055“. This password was encrypted by md5() function from the real password “1234“.

    * When you test this script you must to put the real password (1234) in “password” box.

index.php

The mainly file for do 3 things.

  • Login form. Including 2 fields “username” and “password” and submit button “Login”.
  • Login authorize program. Do authorize check after you submit form, if passed in username and password, this page will re-direct to main.php. If not, show the invalid user or password message.
  • Logout. Clear the login session when come back or refresh this page.

Read more…