【问题标题】:How to add sessions in my php code如何在我的 php 代码中添加会话
【发布时间】: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/…

标签: php session


【解决方案1】:

已解决,谢谢各位

<?php
if (isset($_POST['nohp']) AND isset($_POST['msg']))
{
   $noTujuan=$_POST['nohp'];
   $message=$_POST['msg'];
}
else
{
   die("access this page from index.php");
}
  
if (!empty($noTujuan))
{
    echo "No. HP: $noTujuan <br /> Isi Pesan: $message";
}
else
{
   die(sorry, you must entry name");
}
?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多