PHP Variable Echo


PHP Variable Echo

我在里面放了一些变量,现在试着回显它们。

echo $from;
echo $message;
echo $sent_timestamp;

PHP页面一直加载,然后大约10秒后变成空白。

我只是在尝试我的手在PHP,所以我不是那么先进。欢迎提出任何意见或建议。

$error = NULL; 
if (isset($_POST['from'])) {
  $from = $_POST['from']; 
} else { 
  $error = 'The from variable was not set';  
}
/** * Get the SMS aka the message sent. */ 
if (isset($_POST['message'])) { 
  $message = $_POST['message']; 
} else { 
  $error = 'The message variable was not set'; 
} 
/** * Get the timestamp of the SMS */ 
if (isset($_POST['sent_timestamp'])) { 
  $sent_timestamp = $_POST['sent_timestamp']; 
}

在条件中定义变量。只有在满足正确的条件时才会定义变量。

$from = (isset($_POST['from'])) ? $_POST['from'] : "From var not set";
$message = (isset($_POST['message'])) ? $_POST['message'] : 'The message variable was not set';
$sent_timestamp = (isset($_POST['sent_timestamp'])) ? $_POST['sent_timestamp'] : "The time var was not set";

使用此方法可确保无论如何都可以设置变量