我创建了一个应用程序,我想将唯一值/id 从一个页面传输到另一个页面。我在这个过程中使用了 session 。
代码如下:
<?php session_start();?>
<?php
#php code to get values
include_once "process/config.php";
$sql = "select * from posts";
static $i=0;
$result = mysqli_query($conn,$sql);
if($result->num_rows > 0){
while($rows = $result->fetch_assoc()){
$_SESSION["post_row_id"] = $rows["id"]; #Storing post id for updation.
echo $_SESSION["post_row_id"];
?>
<tr class="gradeA">
<td><?php echo ++$i; ?></td>
<td><u><a onmouseover="this.style.color='blue'" onmouseout="this.style.color='black'" href="post_action.php">
<?php echo $rows["post_title"]; ?></a></u></td>
</tr>
<?php
}
}
?>
我想使用 $_SESSION["post_row_id"] 将 row_id 转移到 post_action.php 页面,但每次我点击 anchor 标记时,最后一个 id 被转移到下一页。 但是当我回显 $_SESSION["post_row_id"] 时,会显示所有唯一值。
注意: 我通过在 anchor 标记中传递 id 来做到这一点,它工作正常。但是在 URL 中显示了值,任何人都可以更改该值并传递一些其他数据。 Session 在那个时候是安全的,所以我试图用 session 来做
最佳答案
To stick with your original code,
you can pass parameters on your <a href> tag,
by adding something like this to your url,
<a href="post_action.php?rows_id=$rows_id"></a>
if your goal is just to pass that id to another page, you may remove the session since its no longer needed since the id is already passed on your url,
<?php session_start();?>
<?php
#php code to get values
include_once "process/config.php";
$sql = "select * from posts";
static $i=0;
$result = mysqli_query($conn,$sql);
if($result->num_rows > 0){
while($rows = $result->fetch_assoc()){
$_SESSION["post_row_id"] = $rows["id"]; #Storing post id for updation.
echo $_SESSION["post_row_id"];
?>
<tr class="gradeA">
<td><?php echo ++$i; ?></td>
<td><u><a onmouseover="this.style.color='blue'" onmouseout="this.style.color='black'" href="post_action.php">
<?php echo $rows["post_title"]; ?></a></u></td>
</tr>
<?php
}
}
?>
关于php - 无法将唯一 session 值从一个页面传输到另一个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43863364/