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

Final year project, please point me in the right direction
hi there for my final year project I'm aiming to build a php script shell to use as an expert system

Help with translating C code into assembler code
Hi im doing a project that moves a robot around a maze avoiding walls and need some help with conver

Displaying returned XML in another PHP page
I have an online payment form that will return XML given if a payment is successful or declines. I

Is this possible? If one file assigned to an ID...
I have a page that lists property listings assigned to a specific user (a manage page), with brief t

Pass sql into pl/sql and create RMAN duplicate script.
Hi,

I'm new to pl/sql and I'm trying to write a script that will generate some RMAN comma

read integers that returns a negative or prints the average
Im trying to finish this homework assignment by tommarow afternoon and I keep getting stuck.
Wr

FTP Programs
Here is a list of commonly suggested FTP Programs to use:

FileZilla
SmartFTP
CuteFTP

regex for quoted text within a string
I am still getting the hang of regex expressions, but I cant seem to figure out how I would escape q

How to show the difference between two data field in a database with php.
Hello php gurus,

how r u all... i'm not so well facing a typical problem please help me...<

filesize() returns 0
I have a socket program that runs in an infinite loop, listening for connections, in this socket I h

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