I have a problem with a WordPress session. I have a test.php file that is used to post a variable to a WordPress site. It has the condition: "if a session variable is set, the user can access the entire WordPress site, and if the session variable is not set, the user cannot access the site."
When I submit this variable to the WordPress site using test.php, the page works fine, but when I access the internal pages, for example "xyz.com/contact", I get a Not Access error message, which means the session variable was cleared on the next page.
Here is the test.php file:
<form action="wordpress-site-link" method="POST"> <input type="submit" name="var" value="go"/> </form>
In the themes / theme-name / header.php file, I wrote this code:
session_start(); if(isset($_SESSION['var'])) { echo 'Welcome'; } else if(isset($_POST['var'])) { $_SESSION['var'] = $_POST['var']; } else { echo 'No access...'; exit; }
source share