I want to redirect to a specific page only when accessing the website for the first time.
Also, since the behavior varies depending on the browser, we want to unify it.
I am creating a process using a PHP session and I want the following behavior.
- Redirect to specific page at first access
- Make transitions to other pages as normal
- Redirect to a specific page when revisiting (If i have more than 15 minutes available for convenience)
For English-speaking countries, it is created because it wants to distribute the landing page by determining the browser setting language, but there is also a place where it is reasonable to use the session in the first place, If i have a suggestion, I would appreciate any advice.
For information on how to identify/redirect access from overseas, please refer to this page.
As I was keen on why I didn't choose .htaccess or Javascript, I decided to do it with PHP.
https://kotori-blog.com/php/globalaccess/
If i check with Chrome, the session is not destroyed even if you open it after 15 minutes have passed since closing the tab or closing the browser, and if you look at var_dump ($_SESSION), ['visit'] The value is increasing.
It seems that it's been 15 minutes when you check with FireFox, but it seems that the session is destroyed when you exit the browser.
// functions.php
function redirect () {
// Discard session if more than 15 minutes have passed since last access
if (isset ($_ SESSION ['last_access'])&&(time ()-$_SESSION ['last_access']>60 * 15)) {
$_SESSION = array ();
setcookie (session_name (), '', time ()-42000, '/');
session_destroy ();
}
session_start ();
$_SESSION ['last_access'] = time ();// last access update
// first time redirect
if (! isset ($_ SESSION ['visit'])) {
$_SESSION ['visit'] = 1;
header ("Location:/page I want to skip");
exit;
} else {
// Count to check the status of ['visit']
$visit = $_SESSION ['visit'];
$visit ++;
$_SESSION ['visit'] = $visit;
}
}
// Run at the beginning of each page
<? php
require_once ('functions.php');
redirect ();
?>
<! DOCTYPE html>
<html>
Omitted
Supplemental information
Server
OS: Linux (details unknown, XServer)
PHP: 7.2.17
PC
OS: MacOSX 10.12
Browsers used: Chrome 78.0.3904.108, FireFox 70.0.1
-
Answer # 1
-
Answer # 2
If you check with Chrome, the session will not be discarded even if you close the tab or close the browser and then open it for more than 15 minutes
Maybe Chrome's Window is closed but Process remains.
Check if Chrome.exe remains in Task Manager.Is "Continue background app processing when Google Chrome is closed" enabled in Chrome settings?
Go to chrome: // settings/system and check if the following are enabled: -
Answer # 3
Record the last login time in the session,
If the session is not set or if 15 minutes have passed since the session value, isn't the process redirected?The expiration date of a session or cookie may not be as simple as discarding it when it expires.
The explanation is difficult, but if you google it, it will come out a lot.
Related articles
- php - how to output custom fields to a specific category archive
- i want to remove error checking for specific fields on the cakephp controller side
- php - only applied to specific pages of wordpress custom posts
- [php] extracting a specific part from a multidimensional array
- php - i want to display a list of specific tags in wordpress
- php - regarding redirect processing in laravel
- i want to edit a specific value value in a php associative array
- php - canceling the redirect
- php - if you change the site address on wordpress, it will redirect to other domains without permission
- php - i want to make a specific url an index
- about accessing php files under wordpress "/wp-content/themes/~"
- i want to acquire a specific value by adding a condition to the column value from php db
- php i want to add a deletion function to delete only a specific number on the simple bulletin board
- i want to extract the first 5 cases that meet specific conditions from laravel's relations
- php - i want to exclude/delete a specific tag in the tag list
- i want to group by a specific value between php associative arrays and aggregate them
- php - when accessing the site with curl, get the response of another access in the page
- php - when accessing the web application in lan from a pc in another lan, it cannot be referenced how can i make this visible?
- [php/html] cannot default a specific value in the pull-down
- php - i want to execute a linux command when accessing a website
- php - i'm getting a syntax error, but i don't know the cause i want to identify the cause
- php - what does it mean to copy and paste the code?
- about exporting excel with php
- php - i want to display the carousel slider widget in order of update date and time
- php - please tell me about cookies and sessions in chrome developer tools
- php - i want to extract and display only a part of a web page with file_get_contents
- html - margin-bottom is specified but it is not reflected
- php - post wordpress updates in static html
- answer input in php when the home is clicked, it does not respond
- php - i want to read multiple words with wordpress
Oh!
That's why sessions usually expire when you close your browser.
So if you want to do what you want to do, use cookies or localStorage.