我从数据库中导出了数据并将其存储在php
中<tr>
<td><a href=SMSindex.php?tp_no=$row[tel] >
<img src=images/phone.png width=30 height=30 >
</a>
</td>
<td>".$row["name"]."</td> </tr>
当我点击phone.png图片时,SMSindex.php想要回显他们的电话号码而不显示在URL中。(如果只是使用$ _GET [tel]得到答案但同时我可以在同一时间看到电话号码也没有。)
(苏丹·阿劳登先生解决的问题)
答案 0 :(得分:1)
您可以使用sessions来实现此目标。
这里有语法错误。
<td>".$row["name"]."</td> </tr>
应由
修复<td><?php echo $row['name'] ?></td> </tr>
[或者Hanky웃Panky建议的方式]
您可以通过
在会话中使用它<?php
session_start();
$_SESSION['name'] = $row['name']
?>
通过
在另一页上检索它<?php
session_start();
echo $_SESSION['name'];
?>
更新:
如果您的网址中包含此内容,并希望全局使用tp_no
,那么您应该$row['name']
替换$_GET['tp_no']
http://localhost:88/web/SMSindex.php?tp_no={%27tel:94771122336%27}
你应该通过
获得tp_no$_GET['tp_no']
但我不知道你缠绕{}
更新:
因为您不想在页面中看到该网址。
这是克服它的一个小方法。
<?php
session_start();
if (isset($_GET['tp_no']))
{
$_SESSION['tp_no'] = $_GET['tp_no'];
unset($_GET['tp_no']);
$url = $_SERVER['SCRIPT_NAME'].http_build_query($_GET);
header("Refresh:0; url=".$url);
}
elseif (isset($_SESSION['tp_no']))
{
echo $_SESSION['tp_no'];
session_unset();
session_destroy();
}
else
{
echo "Direct / Illegal Access not allowed";
}
?>
解释版
<?php
session_start(); #Starting the Session
if (isset($_GET['tp_no'])) #Checking whether we have $_GET value from the url
{
$_SESSION['tp_no'] = $_GET['tp_no']; # We are assiging the tp_no to session
unset($_GET['tp_no']); #Here we are unsetting the value that we get from url
$url = $_SERVER['SCRIPT_NAME'].http_build_query($_GET); #Here we are removing gettgint the url and removing the tp_no from it
header("Refresh:0; url=".$url); #Now we are redirecting/refreshing the page with tp_no - As you said you need it :)
}
elseif (isset($_SESSION['tp_no']))
#Here is the else if condition once we refresh the page we won't have $_GET so the it will come inside this loop
{
echo $_SESSION['tp_no']; #Displaying the value that is from the session
session_unset(); #Unsetting the session value for secure
session_destroy(); #Destroying the entire session value for secure
}
else
{
#The compiler will come to this part if both session or url is not set, So this is illegal area
echo "Direct / Illegal Access not allowed";
#There might be some hackers/genius persons who will try to access directly this page, to avoid them we are showing them the above warning message
}
?>