Page 1 of 1

Passing data from a session into a variable

Posted: Mon Mar 24, 2008 12:46 pm
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

Re: Passing data from a session into a variable

Posted: Mon Mar 24, 2008 1:05 pm
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.

Re: Passing data from a session into a variable

Posted: Mon Mar 24, 2008 1:12 pm
by shure
cheers! what a rookie mistake, ill probably be asking more questions as time goes on.

thanks for the help, much appreciated