2015-06-18 123 views
0

我来源于数据库中的数据和存储一样,在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想呼应,他们的电话号码,而不在网址中显示。(如果只使用$ _GET [联系电话]得到答案,但同时我可以在同一个电话没有在网址见也。)

(由Mr.Sulthan Allaudeen问题解决)

+0

不,这是正确的方式,一些小的修正之后。 '{$ row ['tel']}'因为它在字符串 –

+0

内被使用,但我们可以在URL中看到电话号码。我不需要显示 – shanthini

+0

然后将其存储在会话变量中,并在其他页面访问 –

回答

1

您可以使用sessions来实现此目的。

您在这里有一个语法错误。

<td>".$row["name"]."</td> </tr> 

它应由

<td><?php echo $row['name'] ?></td> </tr> 

固定[或方式手帕웃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'] 

但是我不知道你换衣服的原因第二{}

更新:

当你不希望看到页面的URL。

这里有一个微小的变通方法来克服它。

<?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 
} 
?> 
+0

在我的编码中没有语法错误来派生电话号码或姓名,并且它正常工作。每当我将名称和电话号码添加到数据库中时,图像想要为名称创建,当我单击图像时,另一页要回显该号码而不显示URL中的数字。这是我的要求。 – shanthini

+0

你可以显示你在http :: //www.eval.in中的代码吗?这将很容易理解 –

+0

我发送到您的电子邮件。 (类似编码) – shanthini

相关问题