Jump to content

Recommended Posts

Well for my sight, I am making a simple login system. Below is the source of my login.php page. I am experimenting with cookies right now, I was going to us javascript but the PHP functions looked a lot easier.

 

Login.php

<?php
  $username = $_GET['username'];
  $password = $_GET['password'];
  $time = $_GET['time'];

  if ( file_exists('/users/'. $username. '.txt') == FALSE ) {
    $userInfo = file_get_contents('users/'. $username. '.txt');
    list($pass, $rank) = split(',', $userInfo, 2);

    if ($pass = $password) {
      setCookie('loggedIn', "y", time()+3600*$time);
      setCookie('user', $username, time()+3600*$time);
      setCookie('rank', $rank, time()+3600*$time);
    } else {
      setCookie('loggedIn', "n", time()+3600);
    }
  }

if ($_COOKIE['loggedIn'] = "y")
  echo "Yes, ". $_COOKIE['user'];
else
  echo "No"
?>

 

 

If you use the URL 'http://www.mypage.com/login.php?username=Sample&password=Secret', and you have the following doc in your users folder:

 

Sample.txt

Secret,5

 

For some reason, the 'loggedIn' cookie is set, but when it tries to load the cookies 'user' and 'rank', the page returns 'Yes, '. Is there something wrong with my setCookie parameters or something?

 

Thanks for any help,

 

- Andrew B

Link to comment
https://forums.phpfreaks.com/topic/96864-login-system-help/
Share on other sites

1. Don't use $_GET to store login information.

2. Don't use a flat file system for storing passwords.

 

I suggest you start again, using $_POST and a database where the passwords are md5 encrypted.

I've deliberately skirted around your cookie issue I don't think thats the real issue here tbh.

Link to comment
https://forums.phpfreaks.com/topic/96864-login-system-help/#findComment-495699
Share on other sites

why dont u make it a session

 

session start();

 

and start from this

<?
session start();

$username = @$_POST['username']
$password = @$_POST['password']

 

google is your friend

plenty of tuts there

 

www.w3schools.com

youtube.com

 

and some other great ones out there as well

Link to comment
https://forums.phpfreaks.com/topic/96864-login-system-help/#findComment-497071
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.