Passing data from a session into a variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shure
Forum Newbie
Posts: 7
Joined: Fri Mar 14, 2008 10:06 am

Passing data from a session into a variable

Post by shure »

ok i dont want to deter anyone by my rookie knowledge, so i have thought about what i am going to ask.

Im doing a uni exercise at the moment and am trying to replicate the windows lock button feature for a website. It involves clicking on a 'lock' link that takes the current logged in user (using sessions ) to a page where they can only re-enter their password and then they will be re-directed back to the page they were on. This might seem useless, but i want to put this on a website so that if the user can quickly and easily lock access to their account to prevent another user getting on their workstation and changing details etc.

To do this i need to pass the username from the original session into a variable on the 'lock' page, then destroy the session so you cant click the browser back button and go to the previous page. The username stored and password entered can then be compared to the username and password in the database to check the validity of the user and a new session created.

Im a rookie at best, and when i try to use $username = <?=$_SESSION['username']?> there is an error.

If anyone knows an easy way to pass data from a session into a variable, with the session then being destroyed then please let me know.

cheers
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Passing data from a session into a variable

Post by John Cartwright »

All PHP code needs to be wrapped in <?php ?> tags,

Code: Select all

<?php $username = $_SESSION['username']; ?>
<?= is a shortcut for <?php echo, which is not what you wanted either. As for removing the session, I don't think you want to actually remove the session. Instead, store a flag of some kind to indicate their status, whether it's 'active', or 'locked'. Then, however you setup your permissions should check against this flag and not the presence of the session.
shure
Forum Newbie
Posts: 7
Joined: Fri Mar 14, 2008 10:06 am

Re: Passing data from a session into a variable

Post by shure »

cheers! what a rookie mistake, ill probably be asking more questions as time goes on.

thanks for the help, much appreciated
Post Reply