【发布时间】:2015-02-11 05:19:48
【问题描述】:
我在 php 中的会话有问题。
这是 index.php
<form method="post" action="send.php">
No. HP Tujuan : <input type="text" name="nohp" value="+62"><br>
Pesan : <textarea name="msg"></textarea><br>
<input type="submit" name="submit" value="Kirim SMS">
</form>
还有这个send.php
<?php
mysql_connect("dbhost", "dbuser", "dbpass");
mysql_select_db("sms");
$noTujuan = $_POST['nohp'];
$message = $_POST['msg'];
$query = "INSERT INTO outbox (DestinationNumber, TextDecoded, CreatorID) VALUES ('$noTujuan', '$message', 'Gammu')";
$hasil = mysql_query($query);
if ($hasil) echo "SMS Success";
else echo "SMS Failed";
?>
我想创建一个会话,但我不知道如何。我希望 send.php 页面只有在用户已经完成 index.php 中的表单时才能访问。
【问题讨论】:
-
您不需要会话来完成此操作。只需验证是否设置了表单的变量。
if (empty($_POST['nohp'])) { ehco "Please complete form"; }或将它们重定向回 index.php。见stackoverflow.com/questions/15220704/…