嘿,我是 PHP 新手,所以非常希望您能深入了解我是如何编程的,而且我在为会话问题提出解决方案时遇到了麻烦。
我正在为易货交易和本地贸易系统 ( LETS ) 编写脚本,我目前正在编写报价页面,用户可以在其中查看所有提供的产品/服务,然后单击产品/服务以获取更多详细信息。点击产品/服务后,他们可以出价。在 LETS 系统中,成员拥有时间/生活美元,他们可以通过与其他人进行交易来赚取收入。所以它的替代货币几乎是由工作的人创造的(不像我们目前政府使用的法定货币系统)。因此,如果用户拥有 Life Dollars,他们可以向提供其产品/服务的其他用户出价。
我在一个名为offers.php
. 简而言之,将有 4 页由offers.php
. 当用户最初查看报价部分 ( offers.php
) 时,他们会看到所有报价,然后他们可以单击报价 ( offers.php?id=X
),然后单击进行出价 ( offers.php?id=X&action=makebid
),然后确认出价 ( offers.php?id=X&action=confirm
)。
好的,所以我的会话的问题是:当用户从开始offers.php?id=X
到结束时,会话工作。如果他们走他们认为应该没有问题的路线,他们将无法绕过我的验证。但是,如果用户点击说offers.php?id=100
然后offers.php?id=200&confirm
在浏览器地址栏中输入 URL,他们可以绕过我的验证,从而导致两次输入报价(如果他们已经提出报价)。当用户直接转到另一个时也会发生同样的情况offers.php?etc
URL,但这不是什么大问题。我仍然想更正此问题,因为我担心何时将产品/服务页面粘贴到另一个网站上,因为这样会话将无法正常工作。我说的有道理吗?如果需要,我可以解释更多。我喜欢编程,所以尽可能丢掉任何提示/挑战。感谢您抽出宝贵的时间 :)
这是我的offers.php
代码:
<?php
require_once('startsession.php');
require_once('dbconnect.php');
if (!isset($_SESSION['user_id'])) {
echo '<p class="login">Please <a href="login.php">log in</a> to access this page.</p>';
exit();
}
require_once('navmenu.php');
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if (isset($_GET['id']) && $_GET['action'] == 'confirm') {
$adid = $_GET['id'];
$userid = $_SESSION['user_id'];
$cost = $_SESSION['cost'];
$sellerid = $_SESSION['seller_id'];
//Check if bid was already made
$query = "SELECT * FROM transactions WHERE ad_id = '$adid' AND buyer_id = '$userid'";
$data = mysqli_query($dbc, $query);
$row = mysqli_num_rows($data);
if ($row == 1) {
echo '<p>Bid has been made</p>';
} else {
//If bid doesnt already exist insert bid
$query = "INSERT INTO transactions (ad_id, buyer_id, seller_id, cost, status) VALUES ('$adid', '$userid', '$sellerid', '$cost', 'O')";
$data = mysqli_query($dbc, $query);
}
} else if (isset($_GET['id']) && $_GET['action'] == 'makeoffer') {
$adid = $_GET['id'];
$userid = $_SESSION['user_id'];
//Check if bid was already made
$query = "SELECT * FROM transactions WHERE ad_id = '$adid' AND buyer_id = '$userid'";
$data = mysqli_query($dbc, $query);
$row = mysqli_num_rows($data);
if ($row == 1) {
echo '<p>You have already made a bid on this..</p>';
} else {
echo '<form method="post" action="offers.php?id=' . $adid . '&action=confirm">';
echo '<p>You are about to bid 5 Life Dollars.';
echo '<input type="submit" value="Confirm" name="submit" /></p>';
echo '</form>';
}
} else if (isset($_GET['id'])) {
$userid = $_SESSION['user_id'];
//Get ad details
$adid = $_GET['id'];
$query = "SELECT * from ads WHERE id = '$adid'";
$data = mysqli_query($dbc, $query);
$row = mysqli_fetch_array($data);
//echo ad details
echo '<p>' . $row['ad_name'] . '<br>' . $row['ad_desc'] . '<br>' . 'Cost: ' . $row['timedollars']
. ' Time Dollars . ' . '<br>';
//Set session seller and cost
$sellerid = $row['seller_id'];
$_SESSION['seller_id'] = $sellerid;
$_SESSION['cost'] = $row['timedollars'];
//Check to see if a bid was already made
$query = "SELECT * FROM transactions WHERE ad_id = '$adid' and buyer_id = '$userid'";
$data = mysqli_query($dbc, $query);
$row = mysqli_num_rows($data);
if ($row == 0 && $userid != $sellerid) {
echo '<a href="offers.php?id=' . $adid . '&action=makeoffer">Make Bid</a></p>';
} else if ($row == 1) {
echo 'Already bidded';
}
} else {
//Get all ads/offers
$query = "SELECT * FROM ads WHERE ad_type = 'O'";
$data = mysqli_query($dbc, $query);
//echo all ads
while ($row = mysqli_fetch_array($data)) {
echo '<p>' . '<a href="offers.php?id=' . $row['id'] . '">' . $row['ad_name'] . '</a>' . '<br>' . $row['ad_desc'] . '</p>';
}
}
mysqli_close($dbc);
?>
enter code here