2

I'm currently thinking an issues related to PHP cookies.

1) Here is my case. User can sign in and then view my page.

2) Then user stop at page3, user want to sign out and exit.

3) He can save his current page location(page3) in cookies, to make him can directly enter to page3 when he login in the future.

So, may I ask,if i use cookies on this, how should I store it in cookies? For the page location.

Can give me some idea on it?

asked Nov 28, 2015 at 6:54
1

2 Answers 2

1

If you are using PHP I believe you could also use $_SESSION to save his location and login info.

answered Nov 28, 2015 at 7:00
Sign up to request clarification or add additional context in comments.

Comments

0

If you want user to be able to close broswer, open it again and still be signed in, use cookies (with specified expiration time). You can use session if you will be satisfied with fact that as long as user closes the browser he will be signed out.

SETTING THE COOKIE

<?php
$cookie_name = "user";
$cookie_value = "John Doe";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
?>

SESSION USAGE

 session_start(); 

put a user id in the session to track who is logged in

 $_SESSION['user'] = $user_id;

Check if someone is logged in

 if (isset($_SESSION['user'])) {
 // logged in
 } else {
 // not logged in
 }

Find the logged in user ID

$_SESSION['user']

So on your page

 <?php
 session_start();
 if (isset($_SESSION['user'])) {
 ?>
 logged in HTML and code here
 <?php
 } else {
 ?>
 Not logged in HTML and code here
 <?php
 }
answered Nov 28, 2015 at 7:22

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.