Jump to content

Learning sessions, a few questions


spetsacdc

Recommended Posts

Hello, I'm trying to make a simple site where users can login securely using sessions.

 

I want to have a menu bar at the top of the page that displays a login box when you are not logged in and your username when you are logged in.

 

I am trying to plan the best/most efficient way to do this. Could someone explain how this is usually done? I am confused about where I need to include the sessions.php file. I am also not confident how to change the top of the webpage depending on if they are logged in.

 

For security I want to change the session id for the person on each page change and also compare the user-agent. Do I store these in mysql?

 

I haven't found a really good tutorial for this, but I'm looking at

 

http://xqus.com/archives/2004/10/19/secure-php-sessions/

 

Any tips at where to get started would be great.

 

Thanks

 

Link to comment
Share on other sites

No reason to change a users session id.

 

In regards to changing your menu, you can do a simple $_SESSION['uname'] when they log in, and check that value and adjust your menu accordingly.

 

This is one of my side bars

 

<ul>
  <li class="currentlink">Home >></li>
  <li><a class="navlinks"  href="reservations.php">Reservations</a></li>
  <li><a class="navlinks"  href="news.php">News</a></li>
  <li><a class="navlinks"  href="faq.php">FAQ</a></li>
  <li><a class="navlinks"  href="links.php">Links</a></li>
<li><a class="navlinks"  href="register.php">Register</a></li>
<?php
if ($_SESSION['auth']==1)	{
 ?>
<li><a class="navlinks"  href="logout.php">Logout</a></li>
<?php 
}
else	{
?>
<li><a class="navlinks"  href="login.php">Login</a></li>
<?php
}
?>
<?php
if ($_SESSION['role'] == "admin") {
?>
<li><a class="navlinks"  href="admin.php">Admin</a></li>
<?php
}
?>

</ul>

Link to comment
Share on other sites

Thanks. That is actually what I did, but I didn't know if that was secure/the general way of doing it.

 

Now, do you have a sessions.php file that is included on every page? Is that where you place session start?

 

So is this website wrong about changing the session key: http://xqus.com/archives/2004/10/19/secure-php-sessions/

 

"Changing the session key

This is important, in my oppinion you should change the session key for each new request the user makes. If a someone should get the hold of a session key, most likely it will be expired."

 

I am trying to protect against session stealing, but I don't understand it too well.

 

Thanks again

Link to comment
Share on other sites

I don't have a seperate sessions.php file, I just have session_start(); at the top of every page I have.

 

And honestly, if sessions get deleted off the server in a timely manner, I wouldn't even worry about it.

 

 

Now, do you have a sessions.php file that is included on every page? Is that where you place session start?

 

Link to comment
Share on other sites

  • 2 weeks later...
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.