PHP User Authentication Login and password check Tutorial


 

PHP User Authentication Login and password check Tutorial

Remember the form asking you to type your login and password? You can have it on your page too.

Remember the form asking you to type your login and password? You can have it on your page too.

Creating a click counter is pretty simple. All it requires is after the code has been trigger, to add 1 to the given row. Sound easy enough?
The fields being used here are count, which can be inserted as a "SMALLINT(3) NOT NULL", url which can be "VARCHAR (50) NOT NULL", and lastly ID which depending upon your already installed script is up to you. Count is where the number of times a url has been clicked is stored, URL is where the page then redirects to.

<?
#Just some information to be filled out.
#Given table for the code to communicate with.
$table="blah";
#Server where the database is located.
$dbhost="localhost";
#Name to connect to the database.
$dbname="name";
#Password to verify its you.
$dbpass="*****";
#Database to connect with within the sever.
$dbbase="base";

//Now to connect to mySQL.
$connect = mysql_connect("$dbhost", "$dbname", "$dbpass");
mysql_select_db($dbbase, $connect);

//Updates the field "count" where the given
//row was specified, in this case by it's ID.
$update = "UPDATE $table SET count = count + 1, url = url WHERE id='$id'";
$result = mysql_query($update);

//After it added the click it then redirects to the URL.
$query = "SELECT * FROM $table WHERE id='$id'";
$result = mysql_query($query);
$tab=mysql_fetch_array($result);
$url=$tab["url"];
header("Location: $url");
?>

One thing to keep in mind is on line 23:

$update = "UPDATE $table SET count = count + 1, url = url WHERE id='$id'";

I restated the other fields. I would suggest on doing that for all variables(fields). IE you would not have to reinsert ID, though this is just to lessen any confusion. And that's it. You can access it by start to linking sites by http://yoururlhere.com/?id=45 (45 being a variable). Though now you may be wondering what the hell am i going to use that for?
Well, many things (or at least 3).
*) Forum or News script (How many times a post has been read.)
*) Links or Banner Exchange script (How many visitors you have sent to one or you can even reverse it.)
*) Ladder program.(A ladder program can work the same way. A person reports a loss, which adds the given amount of points.)

Ads