Dynadot โ€” .com Registration $8.99

[Resolved] Simple Php/MySQL login script with cookies

Spaceship Spaceship
Watch
simple php/mysql login script with cookies

Please i need a simple php/mysql login script with cookies
any one got any
thx
 
0
•••
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
•••
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
•••
ok thx problem solved
i were able to fix it :)
 
0
•••
Appraise.net
Unstoppable Domains
Domain Recover
DomainEasy โ€” Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back