Jump to content

Recommended Posts

I have my php pages set up like this:

 

1. log in with login.php

 

2. that sends you to main.php

 

3. in main.php, there are links to page-a.php, page-b.php, page-c.php, etc.

 

when you type in a password at login.php, it passes your input to main.php.

 

the correct password is hardcoded in main.php. if it matches, a session variable is set, which should be able to be used on page-a.php, page-b.php, page-c.php, etc. to verify that whoever accesses those pages has gone through the login process. if the session variable doesn't match (or null) the user is redirected to the login page.

 

also the session variable is checked (recursively) when accessing main.php, just like the other pages.

 

the problem is, it's as if each page starts over. the session variable does not make it beyond the page that sets it. it should be passed on to the next page but it's not.

 

I used an echo statement in page-a.php to verify and rem'd out the rest of the code. no echo because session value is null, page goes on to load the html. without the code rem'd out it redirects the user to login.php.

 

code:

 

LOGIN.PHP

<?
session_start();  
if(isset($_SESSION['aaa']))
unset($_SESSION['aaa']); 
?>
<html>
<head>
<title>title</title>
</head>
<body>
<table width="400" align="center" border="0" bordercolor="#000099" bordercolordark="#000066" bordercolorlight="#6666FF">
  <tr bgcolor="#B0C4DE"> 
    <td> 
      <form action="main.php" method="POST">
        <p align="center"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif" color="#FFFFFF"><br>
          Password</font></strong> 
          <input name="pwfield" type="password" value size="20" maxlength=20>
<input type="submit" value="Login"></p>
      </form>
    </td></tr></table>
</body></html>

 

MAIN.PHP

<?
if ($_SESSION['aaa']!="abcdef")
{
$password="twinkies";
if ($_POST["pwfield"]==$password)
$_SESSION['aaa']="abcdef"; // successful login
else 
{header("Location: login.php"); exit();}
}
?> 
<html>
<head>
<title>title</title>
</head>
<body>
<a href="page-a.php">Page A</a>
<a href="page-b.php">Page B</a>
<a href="page-c.php">Page C</a>
</body></html>

 

PAGE-A.PHP

<?
echo $_SESSION['aaa'];
//if ($_SESSION['aaa']!="abcdef")
//header("Location: login.php");
//exit();
?>
<html>
<head>
<title>title</title>
</head>
<body>
...

Link to comment
https://forums.phpfreaks.com/topic/222041-passing-session-to-the-next-page/
Share on other sites

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.