Home N-13 News Forums Help Search
RegisterForgot password?
How to add image to post necklacesdiscou
Known bugs - 4.0.3 necklacesdiscou

Latest N-13 News 4.0.3

What is N-13 News?
Where can I get help?
Known bugs

Forums Tutorials Simple user login system
1 2
Chris
Posted on 12 Apr 2008, 20:33:10

Access: Admin
Total Posts: 1395
Joined: 2006-05-19

If your timezone is a 5 hour difference what you need to do is work out how many seconds are in 5 hours, 60 seconds in a minute, 60 minutes in an hour, 5 hours so 60*60*5=18000 and if your 5 hours behind you enter -18000

Also if your going to use my news script I'd recommend using the latest version I just released today :)

http://network-13.com/thread/9357eb9c4bb506bb
#160
Last edited by Chris at 2008-04-12 20:36:50 Reason:
Natrs
Posted on 19 Mar 2009, 15:53:03

Access: Member
Total Posts: 1
Joined: 2009-03-19

Hi, I have a problem when using this script, please help....

Quote:
Fatal error: [] operator not supported for strings in /home/www/loginchck.php on line 3


here is loginchck.php

Code:
<?php
session_start();
$name[] = "XXX"; $pass[] = "XXX";
#create an array of usernames and passwords
#add as many as you want


#used for the logout link, changes the session 'loggedin' = false if ?action=logout
if($_GET['action'] == "logout"){
$_SESSION['loggedin'] = false;
$_SESSION['username'] = "";
}

if (($_SESSION[loggedin])== false){
if(!$_POST['submit']){
header('Location: login.php');
}else{
#username check
$tmpname = $_POST['username']; #the username the user has submitted
$tmppass = $_POST['pass']; #the password the user has submitted

$t = count($name); #count the total users
$i = 0;
#create a loop to go through each username/password and compare it with the name pass which was submitted
while($i <= $t){
if($tmpname !== "" || $tmppass !== ""){
if($tmpname == $name[$i] && $tmppass == $pass[$i]){
#if the name/pass submitted matches any of the username and passwords set the session 'loggedin' = true
$_SESSION['loggedin'] = true;
$_SESSION['username'] = $name[$i];
header('Location: ?'); #reload the page
}
}
$i++;
}
echo "Invalid Username or Password 0.o";#show an error message if the user enters an incorrect name/pass
}
die;
}
?>

Welcome <?php echo $_SESSION['username']; ?>.<br>
<a href="?action=logout">Logout</a><br><br>

#522
Djdog
Posted on 12 May 2009, 22:15:20

Access: Member
Total Posts: 2
Joined: 2006-09-24

Code:
$name = array();
$pass = array();

I added that.

So it looks like;

Code:

<?php
session_start
();
$name = array();
$pass = array();
#535
Kamilniyazi
Posted on 22 Jul 2010, 17:01:45

Access: Member
Total Posts: 3
Joined: 2010-07-22

Hey Chris,

Thanks for this wonderful system!

In that simple user login system; what should we do to all names&pass from db instead of "$name[] = "Chris"; $pass[] = "123456";" etc.?

thanx
#2741
Chris
Posted on 22 Jul 2010, 17:03:24

Access: Admin
Total Posts: 1395
Joined: 2006-05-19

Quote:
Hey Chris,

Thanks for this wonderful system!

In that simple user login system; what should we do to all names&pass from db instead of "$name[] = "Chris"; $pass[] = "123456";" etc.?

thanx


There's no easy way of doing this, you would need to build a form that first inserts the information into the database then add completely new code to read it and check against it when the user logs in.
#2742
Kamilniyazi
Posted on 22 Jul 2010, 23:30:22

Access: Member
Total Posts: 3
Joined: 2010-07-22

Quote:
There's no easy way of doing this, you would need to build a form that first inserts the information into the database then add completely new code to read it and check against it when the user logs in.

Actually, what i'm looking for is, to show a category to everyone which is a default setting, but showing one spesific category only to registered users. What do you prefer me to do than?
#2744
Kamilniyazi
Posted on 25 Jul 2010, 01:59:01

Access: Member
Total Posts: 3
Joined: 2010-07-22

I figured my problem and created a new login system using the database of N-13:

Login.php:
Code:
<?php 
        session_start
();
        
// dBase file
require_once 'news/db.php';
require_once 
'news/config.php';
require_once 
'news/functions.php';

        if (
$_GET["op"] == "login")
  {
  if (!
$_POST["username"] || !$_POST["password"])
        {
        die(
"You need to provide a username and password.");
        }
  
  
// Create query
  
$pas = md5(SALT . $_POST['password']);
  
$q = "SELECT * FROM `news30_users` "
        
."WHERE `user`='".$_POST["username"]."' "
        
."AND `newpass`= '$pas' "
        
."LIMIT 1";
  
// Run query
  
$r = mysql_query($q);

  if ( 
$obj = @mysql_fetch_object($r) )
        {
        
// Login good, create session variables
        
$_SESSION["valid_id"] = $obj->uid;
        
$_SESSION["valid_age"] = $obj->profile_age;
        
$_SESSION["valid_user"] = $_POST["username"];
        
$_SESSION["valid_time"] = time();

        
// Redirect to member page
        
Header("Location: mods.php");
                }
  else
        {
        
// Login not successful
        
die("Sorry, could not log you in. Wrong login information. $pas");
        }
  }
        else
  {
//If all went right the Web form appears and users can log in
  
echo "<form action=\"?op=login\" method=\"POST\">";
  echo 
"Username: <input name=\"username\" size=\"15\"><br />";
  echo 
"Password: <input type=\"password\" name=\"password\" size=\"8\"><br />";
  echo 
"<input type=\"submit\" value=\"Login\">";
  echo 
"</form>";
  }

?>


Mods.php: (members only content)
Code:
<?php 
session_start
();

if (!
$_SESSION["valid_user"])
        {
        
// User not logged in, redirect to login page
        
Header("Location: login.php");
        }

// Member only content
// ...
// ...
// ...

// Display Member information
echo "<p>User ID: " . $_SESSION["valid_id"];
echo 
"<p>Username: " . $_SESSION["valid_user"];
echo 
"<p>Age: " . $_SESSION["valid_age"];
echo 
"<p>Logged in: " . date("m/d/Y", $_SESSION["valid_time"]);

// Display logout link
echo "<p><a href=\"logout.php\">Click here to logout!</a></p>";

?>


Logout.php: (to logout)
Code:
<?php 
session_start
();
session_unset();

session_destroy();
// Logged out, return home.
Header("Location: index.php");

?>


I hope these codes are helpful for who wants to have a members only page with the db settings of this wonderful n-13 news.

Any thoughts?
#2763
Mingwingming
Posted on 13 Oct 2010, 13:31:44

Access: Member
Total Posts: 4
Joined: 2010-08-25

This looks like just what i need but unfortunately I am not understanding the process of enabling only logged in users to view information.
I am trying not to be too stupid here but i have messed about with the scripts above and not had much joy.. Would someone mind starting from beggining to end on which way is the best way and where to put the files or php code for a stupid simple man like myself :) I would be very grateful.


#2937
sandjuks112
Posted on 15 Jun 2013, 16:25:04

Access: Member
Total Posts: 2
Joined: 2013-01-09

Is it posible, to make this login, with mysql database connection ? From news30_users.

#4035
Chris
Posted on 17 Jun 2013, 12:49:14

Access: Admin
Total Posts: 1395
Joined: 2006-05-19

sandjuks112,

See here http://www.network-13.com/thread/774-Login-Form

#4036
1 2
Network-13.com © 2013