kittencornball
kittencornball

Reputation: 31

PHP cookies / actions

I'm trying to store a cookie on my login.php page so i can keep users logged in. but they aren't showing up... this is just a test one but eventually i would like to store the username/password so the user can stay logged in when they close out of the browser.

Login.php

<?php

if ($_GET["action"]=="loginAction"){

    setcookie('cookie','yum',time()+3600, '/');

}

?>

<form enctype="multipart/form-data" action="/SITE/index.php?action=loginAction" method="POST">
    <input type="text" name="username"  placeholder="Name">
    <input type="password" value="" name="password" placeholder="Password">
    <button id="hideme" name="submit" type="submit">Login</button>
</form>

Upvotes: 1

Views: 174

Answers (3)

kittencornball
kittencornball

Reputation: 31

@Roman

Are you talking something like this

<?php
    setcookie('cookie','yum',time()+3600);
    echo $_COOKIE["cookie"];
?>

my url : site.com/site/index.php?action=loginAction

Upvotes: 0

maesbn
maesbn

Reputation: 207

Be aware the the user can manipulate a cookie. You should take a look at sessions (http://php.net/manual/en/session.examples.basic.php). You could consider them as cookies on the serverside. But then be aware of session hijacking... (https://en.wikipedia.org/wiki/Session_hijacking)

Upvotes: 1

Roman
Roman

Reputation: 2549

setcookie needs to be output before any other output to the browser. It looks like you are trying to use setcookie inside of a script.

You can check if the cookie is set, if output the result of setcookie.

Upvotes: 0

Related Questions