Jump to content

Recommended Posts

I have a quick Question guys about a code i am using!

 

Basicly i have a from which call the login.php which should create a cookie and display Welcome $_cookie['username'] but it doesnt seem to work?

If anyone here spots my error please call me on in.

 

<form name="login" method="post" action="scripts/login.php">
      Username:
      <input type="text" name="username">
      <br>
      Password:
      <input type="password" name="password">
      <br>
      Remember Me:
      <input type="checkbox" name="rememberme" value="1">
      <br>
      <input type="submit" name="submit" value="Login!">
    </form>

 

Login.php

 

<?php
/* These are our valid username and passwords */
$user = 'guest';
$pass = 'guest';

if (isset($_POST['username']) && isset($_POST['password'])) {
    
    if (($_POST['username'] == $user) && ($_POST['password'] == $pass)) {    
        
        if (isset($_POST['rememberme'])) {
            /* Set cookie to last 1 year */
            setcookie('username', $_POST['username'], time()+60*60*24*365, '/account', 'c:/wamp/www/notemapper');
            setcookie('password', md5($_POST['password']), time()+60*60*24*365, '/account', 'c:/wamp/www/notemapper');
        
        } else {
            /* Cookie expires when browser closes */
            setcookie('username', $_POST['username'], false, '/account', 'c:/wamp/www/notemapper');
            setcookie('password', md5($_POST['password']), false, '/account', 'c:/wamp/www/notemapper');
        }
        header('Location: ../index.php');
        
    } else {
        echo 'Username/Password Invalid';
    }
    
} else {
    echo 'You must supply a username and password.';
}
?>

 

 

here is how i am testing to see if my cookies are being set which they arnt!

 

 <?php
  if (isset($_COOKIE['username'])) {
      echo $_COOKIE['username'];
  }
  else {
      include("widgets/login.html");
  }
  //This is just to see if the cookie is set?
  echo $_COOKIE['username'];
      ?>

Link to comment
https://forums.phpfreaks.com/topic/259301-cookie-login-question/
Share on other sites

If you havn't already I would get used to using the php manual, it's real quick and easy to find what you need. In this case, the parameters of the function setcookie:

http://php.net/setcookie

 

Just drop the last two parameters until you understand exactly why your using them :).

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.