How do I refer to a set php session variable in an auto refreshing div?
<?php
//display the bid button if a user is logged in
if (isset($_SESSION['username'])) {
?>
<form class='bidForm' action='bid.php?id=<?php echo $item_id; ?>' method='POST'>
<input class='bid' type='submit' value='BID' />
</form>
<?php
} else {
}
?>
I am making a auction site where if the user bids on an item, the expiration time for the auction item increases by a certain amount. I have set up a bid button for each item that is currently active on the auction and I have to make it so the bid button is only visible (at least the working one - changes to a login button when hovered over while no user is logged in) to logged in users. And as you can see, I have used a isset(SESSION) if else statement above at the moment. I also have the div that contains the active auction items constantly getting refreshed every second through jQuery so that the countdown is being refreshed every second. (it's an auction type where when users bi开发者_StackOverflowd when the timer is below 20 seconds, the timer gets reset to 20 seconds)
The problem is, for some reason the jQuery refreshing actually cancels out the session for some reason (at least in the part where it is getting refreshed) and the bid button disappears after the first second. I can't create an else statement saying that if the session was not set, to now set it because then non-logged in users could see the bid button as well. And I can't create some url variable to refer through GET because then non-logged in users could manipulate that to make the bid button visible for them. And finally, I can't use javascript or prefer not to as I don't want the bidding function to be unavailable for people who have javascript turned off.
What are my options?
Are you sure you did session_start()
in this specific page as well?
Else you cannot access $_SESSION
. Could be this.
/David
精彩评论