如何在我的php代码中添加会话


How to add sessions in my php code

我在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";
?>

我想创建一个会话,但我不知道如何创建。我希望只有当用户已经在index.php.

中完成表单时,send.php页面才能访问

解决了,谢谢各位

<?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");
}
?>