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
48
Other forums
need help in mysql_num_rows()
please tell me what i am doing wrong in this query. it displays this error
Code: Warning: mys
I have a parse error in this query help..
Code: $query1="INSERT INTO `rating` (`item_name`, `rating`, `ip_address`, `date_rated`) VALUES
MS Exchange 2007 integration with ECC 6.0
Hello Experts,
We have ECC 6.0 and MS Exchange 2007. We need to integrate ECC 6 and MS Excha
How to get all server headers like Live http Headers does
Hey all, like many of you I use the Firefox addon "Live http Headers". I'm trying to write
help with multi-update
Now sure how to ask this really....
10g database if that matters.
I have a customer
Procedural to OOP
John Kleijn said that to avoid writing "crappy code", we should learn OOP and common OO pr
Transferring session variables into MySQL
I am trying to transfer $_SESSION variables into MySQL. However there is an error in my MySQL statem
Add trigger to UpdatePanel programmatically
Hi,I'm working on a website which uses AJAX and Masterpages. What I have is an AJAX UpdatePanel whi
disable all input buttons
Hello Friends,
suppose i do have a file ( file.php ) has a submit button
Code: [Sele
disabling a button server-side then re-enabling client-side breaks button postback
I have a tabbed container and a button (not in the container) on a page. If the first tab is selecte