Jump to content

jje

Moderators
  • Posts

    2,755
  • Joined

  • Last visited

  • Days Won

    10

Posts posted by jje

  1. Unlike other languages such as ASP.NET, you do not need to compile PHP applications - you simply create a single file per page.

     

    In the tutorial I posted earlier, you need to create a few files:

    main_login.php - This will be similar to your second snapshot you posted earlier.

    check_login.php - This will not be a page, but simply handle the login information received from main_login.php.

    login_success.php - This will be similar to your first snapshot you posted earlier.

     

    But first, you need to create a MySQL Database and create/assign users to it. Learn more here.

     

    Then, in phpMyAdmin (click on the link in your cPanel home), click on your newly created database and click on the 'SQL' tab. In the box, paste:

     

    CREATE TABLE `members` (
    `id` int(4) NOT NULL auto_increment,
    `username` varchar(65) NOT NULL default '',
    `password` varchar(65) NOT NULL default '',
    `posts` varchar(65) NOT NULL default '',
    `thread` varchar(65) NOT NULL default '',
    PRIMARY KEY (`id`)
    ) TYPE=MyISAM AUTO_INCREMENT=2;

     

    To insert a new user:

    INSERT INTO `members` VALUES (1, 'john', '1234', '0', '0');

     

    Create a new file called 'check_login.php' and paste in via Code Edit:

    <?php
    $host="localhost"; // Host name 
    $username=""; // Mysql username 
    $password=""; // Mysql password 
    $db_name="test"; // Database name 
    $tbl_name="members"; // Table name
    
    // Connect to server and select databse.
    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");
    
    // username and password sent from form 
    $myusername=$_POST['myusername']; 
    $mypassword=$_POST['mypassword'];
    
    // To protect MySQL injection (more detail about MySQL injection)
    $myusername = stripslashes($myusername);
    $mypassword = stripslashes($mypassword);
    $myusername = mysql_real_escape_string($myusername);
    $mypassword = mysql_real_escape_string($mypassword);
    
    $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
    $result=mysql_query($sql);
    
    // Mysql_num_row is counting table row
    $count=mysql_num_rows($result);
    // If result matched $myusername and $mypassword, table row must be 1 row
    
    if($count==1){
    // Register $myusername, $mypassword and redirect to file "login_success.php"
    session_register("myusername");
    session_register("mypassword"); 
    header("location:login_success.php");
    }
    else {
    echo "Wrong Username or Password";
    }
    ?>

    Replace the value of $username $password $db_name with the correct info. Username and DB_Name should be prefixed with your cPanel username.

     

    Rename the page with screenshot 1 to login_success.php. Then Code Edit it. Add this to the very top of the page:

    <? 
    session_start();
    if(!session_is_registered(myusername)){
    header("location:main_login.php");
    }
    ?>

     

    Then replace the username with

    <?php echo $_SESSION['username']; ?>

     

    Rename the page with screenshot 2 to main_login.php. Then Code Edit it. Wrap the two input/text boxes with...

    <form method=post action=check_login.php>
    ...

     

    Then add the attributes to the text box and password field:

    name=username

    name=password

     

    If you wish to create a forum, follow the tutorial at:

    http://www.phpeasystep.com/phptu/12.html

  2. More cron runs == Higher server load == Slower server

     

    djbob rarely gives away free cron jobs, due to the reason above. Why not use Geoff/byron's methods? They basically replicate the setup you desired.

×
×
  • Create New...