[Resolved] Simple Php/MySQL login script with cookies

SpaceshipSpaceship
SpaceshipSpaceship
NamecheapNamecheap
Watch
Impact
35
simple php/mysql login script with cookies

Please i need a simple php/mysql login script with cookies
any one got any
thx
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
What about with session?

login.php :
PHP:
<?php
// get input
$u=$_POST['u'];
$p=$_POST['p'];

// Database check
$q=sprintf(" SELECT id FROM user WHERE username='%s' AND password='%s' ",$u,$p);
$q=mysql_query($q);
if (mysql_num_rows($q)>0) {
   // matched data
   $r = mysql_fetch_row($q);
   $id = $r[0];
   session_start();
   $_SESSION['user_id'] = $id;
   header("Location: home.php");
   die('');
   exit;
}
?>
----- BREAK -----

home.php
PHP:
<?php
if (!isset($_SESSION['user_id']) || $_SESSION['user_id']=='') {
   header("Location: login.php");
   die('');
   exit;
}
// display your main "home.php" from below
?>
<html>
<h1>Welcome, our lovely member</h1>
----- BREAK -----

logout.php
PHP:
<?php
$_SESSION['user_id']='';

header("Location: index.php");
?>
 
Last edited:
0
Close
At least sanitize the data before using it in a mySQL query. With what you have provided I could circumvent it within seconds.

What sort of login script do you need? And is there a reason you are specifically wanting to use cookies (although this is the default method for PHP's sessions).
 
0
Close
ok thx problem solved
i were able to fix it :)
 
0
Close
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back