如何在自动刷新 div 中引用设置的 php 会话变量?

发布于 2024-11-30 01:53:19 字数 856 浏览 0 评论 0原文

<?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 {

}
?>

我正在制作一个拍卖网站,如果用户对某个物品出价,则该拍卖物品的到期时间会增加一定量。我已经为当前在拍卖中处于活动状态的每件物品设置了一个出价按钮,并且我必须将其设置为仅可见出价按钮(至少是工作按钮 - 在没有用户登录时将鼠标悬停在其上时更改为登录按钮in) 到已登录的用户。正如您所看到的,我目前在上面使用了 isset(SESSION) if else 语句。我还有包含活动拍卖物品的 div,通过 jQuery 每秒不断刷新,以便倒计时每秒刷新。 (这是一种拍卖类型,当用户在计时器低于 20 秒时出价时,计时器会重置为 20 秒)

问题是,由于某种原因,jQuery 刷新实际上取消了会话(至少在以下部分)它正在刷新)并且出价按钮在第一秒后消失。我无法创建一个 else 语句来说明如果未设置会话,则现在设置它,因为这样非登录用户也可以看到出价按钮。我无法创建一些 url 变量来通过 GET 引用,因为非登录用户可以操纵它以使出价按钮对他们可见。最后,我不能使用 JavaScript,或者不想使用 JavaScript,因为我不希望关闭 JavaScript 的人无法使用出价功能。

我有什么选择?

<?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 bid 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

や三分注定 2024-12-07 01:53:19

您确定您也在该特定页面中执行了 session_start() 吗?

否则您无法访问$_SESSION。可能是这个。

/大卫

Are you sure you did session_start() in this specific page as well?

Else you cannot access $_SESSION. Could be this.

/David

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文