Need help making login verification cleaner...


Posted on 16th Feb 2014 07:03 pm by admin

I use the below to verify user login. I first check the cookie for the id, ip and a unique id. If it's set then I move on to verifying that they all belong together. I usually copy and paste everything on a page that needs verification and I just edit the "we are good...." part.

Login verification
<?php
//Check to see if cookie is set
if (isset($_COOKIE['id']) && isset($_COOKIE['ip']) && isset($_COOKIE['uniqueid'])){

$cookieid = $_COOKIE['id'];
$cookieip = $_COOKIE['ip'];
$cookieuniqueid = $_COOKIE['uniqueid'];

require('header.php');

//Select id and loginip according to cookie uniqueid
$query = "SELECT * FROM user WHERE uniqueid = '$cookieuniqueid' LIMIT 1";

if ($result = mysql_query ($query)) {
while ($row = mysql_fetch_array ($result)) {
$id = $row['id'];
$uniqueid = $row['uniqueid'];
$ip = $row['ip'];
}
}

//Compare cookie ip and id with query loginip and id --- if cookies match database then we allow
if ($_COOKIE['id'] == $id && $_COOKIE['ip'] == $ip && $_COOKIE['uniqueid'] == $uniqueid) {
?>
we are good....
<?php

require('footer.php');
//End cookie compare
}
//Redirect to index if cookie compare fails
else {
header('Location: index.php');
}
//End cookie set
}
//Redirect to index if cookie is not set
else {
header('Location: index.php');
}
?>

I was wondering if there was a way for me to just do something like:

<?php
require('verify.php');
//If not logged in user wont see the below..
?>
Login user sees this

No comments posted yet

Your Answer:

Login to answer
268 Like 48 Dislike
Previous forums Next forums
Other forums

data type in column definition
Hi,
I create a table with column called "Direction of Travel code ".
The travel codes in t

dropdown box help - open php files to textarea
Hi, I am using tinymce to edit content located in several php files. The code I attached works but i

Greek characters in php
Hi,

I'm making a script and I m using for first time greek characters.
I started to write

Multiple if statements
Ok so seems basic but for some reason I'm not doing it right. What I want is to be able to have 2 se

Really need helps regarding Pagination with Sort
I need someone helps regarding pagination problem...i actually want to make my page limited to let s

Variable Clash
In the past I've had variables clash. For example:

Code: <?php
$c = 5;
$ca

How to pass parameter to tag query?
Hi,
I want to get the value of a tag at a specific time (like 10/27/09 15:29:59), I need to giv

Trouble verifying database password
Thankyou to everyone who responded to my last post (I can't find the posting, it has been buried). <

iterating through an array and escape each value independently.
I have a set up where the variable being escaped is an array and it needs to be iterated and escaped

EU VAT Package 2010
Does any one know whether SAP will be developing new reporting functionality due the new VAT rules t

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash