• Forum
  • Doc
  • Screenshots
  • Download
  • Donate
  • Contributors
  • Contact
  • Follow @phpfreechat
  • DEMO
  • Board index ‹ Version 1.x branch ‹ Contributions (v1.x)
  • Change font size
  • FAQ
  • Register
  • Login

Login system

Post a bug fix, a new feature, a theme ...

Moderators: OldWolf, re*s.t.a.r.s.*2

Post a reply
6 posts • Page 1 of 1

Postby Mgccl » Sun Apr 30, 2006 5:30 am

This is an mod... for people who uses PHPfreechat and want to have an login system...

THIS IS UNFINISHED ARTICLE... I WILL UPDATE IT WHEN I HAVE TIME(like tomorrow)

This is the main idea of a login system(and some code) for noobies to understand
first... you got to make 2 new php files...
login.php
check.php
login.php have a form, which have a place to put username and password and POST to check.php..

check.php wrote:You must first make a database for phpfree chat...

session making
Code: Select all
<?php
session_start();
$_SESSION['username'] = $_POST['username']
$_SESSION['password'] = $_POST['password']
?>

SQL connect
if you understand PHP you know you have to change some of this part to suit your need
Code: Select all
<?php
$sql = mysql_connect("localhost", "mysqluser", "mysqlpass") or die(mysql_error());
mysql_select_db("phpfreechat") or die(mysql_error());
?>

SQL Query
Code: Select all
<?php
$query = "SELECT pass " .
"FROM user " .
"WHERE name='$_SESSION['username']"
mysql_select_db("phpfreechat") or die(mysql_error());

$result = mysql_query($query) or die (mysql_error());

$read = mysql_fetch_array($result);
extract ($read);

if $pass=$_SESSION['password']
{
"echo <a href=chat.php>click here to continual</a>";
}
else
{echo "Wrong password";
}
?>


Let the chat.php must recive $_SESSION['username'], or it will just not work(I will post it up later)

ok.. that's the 1st php code I have ever used involved Mysql
Last edited by Mgccl on Sun Apr 30, 2006 5:39 am, edited 1 time in total.
Mgccl
Member
 
Posts: 35
Joined: Sun Apr 16, 2006 9:40 pm
Top

Postby Munk » Sun Apr 30, 2006 10:21 pm

some things:

you shouldn't set the session vars until you've validated the username/password combination, else someone could set those via POST and then just manually go to chat.php and be logged in. At least you should unset $_SESSION if the passwords don't match.

your query:
$query = "SELECT pass " .
"FROM user " .
"WHERE name='$_SESSION['username']"

should be:
$query = "SELECT pass " .
"FROM user " .
"WHERE name='$_SESSION['username']'";

(note additional single-quote and semicolon. what you have should parse error.)
Last edited by Munk on Sun Apr 30, 2006 10:22 pm, edited 1 time in total.
Munk
New member
 
Posts: 4
Joined: Sat Apr 29, 2006 12:43 am
Top

Postby Mgccl » Mon May 01, 2006 1:09 am

good.... you currected some of my errors...
I'm just an amature PHPer so I might make lots of mistakes
Mgccl
Member
 
Posts: 35
Joined: Sun Apr 16, 2006 9:40 pm
Top

Postby Tribalx » Sun Apr 15, 2007 11:45 pm

A couple of things:

Code: Select all
<?php
session_start();
$_SESSION['username'] = $_POST['username']
$_SESSION['password'] = $_POST['password']
?>

Should be:
Code: Select all
<?php
session_start();
$_SESSION['username'] = addslashes($_POST['username']);
$_SESSION['password'] = addslashes($_POST['password']);
// you dont want any sql injections so you should add slashes in your globals (this is needed at all global (POST,GET,SESSION etc)

// you also need to crypt(md5/sha1/crypt etc) your pass becaus you DONT want to see peoples password! (security issue)
?>

Code: Select all
<?php
$query = "SELECT pass " .
"FROM user " .
"WHERE name='$_SESSION['username']"
mysql_select_db("phpfreechat") or die(mysql_error());

$result = mysql_query($query) or die (mysql_error());

$read = mysql_fetch_array($result);
extract ($read);

if $pass=$_SESSION['password']
{
"echo <a href=chat.php>click here to continual</a>";
}
else
{echo "Wrong password";
}
?>

Should be:
Code: Select all
<?php
mysql_select_db("phpfreechat");
$query = mysql_query("SELECT * FROM user WHERE name='".$_SESSION['username']."' AND pass = '".$_SESSION['password']."' ) or die(mysql_error());
$read = mysql_num_rows($query); // a less complicated query wich saves some time

if ($read == 1) // check if query has a match and contineu
{
echo '<a href=chat.php>click here to continual</a>';
}
else // else unset the session, and send them back to the login page
{
echo "Wrong password";
$_SESSION['username'] = '';
$_SESSION['password'] = '';
header ("Location: login.php");
exit;
}
?>

comments are in the modified codes.
Last edited by Tribalx on Sun Apr 15, 2007 11:55 pm, edited 1 time in total.
watsup doc? :mad:
Tribalx
Member
 
Posts: 13
Joined: Sat Apr 14, 2007 9:54 pm
Top

Postby serge_ » Mon Sep 10, 2007 4:48 pm

Hello!!!

I've tried to implement this one, but the chat always took the first login "guest.." and dont change it when i pass the new parameter,

i've used

$params["nick"] = $username;
$params["nick"] = "$username";
$params["nick"] = "$_SESSION('username')";
$params["nick"] = $_SESSION('username');

i've tried to pass

a href=chat.php?username.....

but none works.. please help me!!!
serge_
New member
 
Posts: 2
Joined: Thu Sep 06, 2007 11:53 pm
Top

Postby gamary » Thu Sep 13, 2007 3:09 pm

Je ne comprend pas grand chose a l'installation ce système de login...
Est ce que quelqu'un pourrai m'expliquer plus en détail ?
gamary
Member
 
Posts: 12
Joined: Fri Sep 07, 2007 4:00 pm
Top


Post a reply
6 posts • Page 1 of 1

Return to Contributions (v1.x)

Who is online

Users browsing this forum: No registered users and 9 guests

  • Board index
  • The team • Delete all board cookies • All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
Sign in
Wrong credentials
Sign up I forgot my password
.
jeu-gratuit.net | more partners
Fork me on GitHub