PHP:无法发布数据?

PHP:无法发布数据?,php,arrays,post,Php,Arrays,Post,我无法从我的PHP脚本发送POST请求。所以我的PHP脚本是 <?php if (isset($_POST)) { // form validation vars $formok = true; $errors = array(); // sumbission data $ip1 = $_SERVER['REMOTE_ADDR']; $ip2 = $_SERVER['HTTP_X_FORWARDED_FOR']; $ip3 = $_SERVER['HTTP_FORWARDED']

我无法从我的PHP脚本发送POST请求。所以我的PHP脚本是

<?php

if (isset($_POST))
{

// form validation vars

$formok = true;
$errors = array();

// sumbission data

$ip1 = $_SERVER['REMOTE_ADDR'];
$ip2 = $_SERVER['HTTP_X_FORWARDED_FOR'];
$ip3 = $_SERVER['HTTP_FORWARDED'];
$ua = $_SERVER['HTTP_USERAGENT'];
$date = date('d/m/Y');
$time = date('H:i:s');

// form data

$action = "sendsms";
$user = "user";
$password = "pass";
$from = $_POST['sender'];
$to = $_POST['to'];
$text = $_POST['msg'];

// validation of recepient

if (empty($to))
    {
    $formok = false;
    $errors[] = "I don't know where to deliver the message :(";
    }
elseif (!filter_var($to, FILTER_VALIDATE_INT))
    {
    $formok = false;
    $errors[] = "Sorry, but I am unaware of that recepient :(";
    }

// validation of sender ID

if (empty($from))
    {
    $formok = false;
    $errors[] = "I don't know the address from where to deliver the message :(";
    }
elseif (strlen($from) < 13)
    {
    $formok = false;
    $errors[] = "Sorry, I couldn't handle the sender ID, it's too long :(";
    }

// validation of message

if (empty($message))
    {
    $formok = false;
    $errors[] = "I don't know what message to deliver :(";
    }
elseif (strlen($message) < 160)
    {
    $formok = false;
    $errors[] = "Sorry, I couldn't handle that message, it's too long :( ";
    }

// Send SMS if all is ok

if ($formok)
    {
    $postData = array(
        'action' => $action,
        'user' => $user,
        'password' => $password,
        'from' => $from,
        'to' => $to,
        'text' => $text,
    );

    // create post body

    $post_body = '';
    foreach($postData as $key => $value)
        {
        $post_body.= urlencode($key) . '=' . urlencode($value) . '&';
        }

    $post_body = rtrim($post_body, '&');

    // Initialize CURL data to send via POST to the API

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://www.example.com/http-api.php");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_body);

    // Execute CURL command and return into variable ch

    $result = curl_exec($ch);
    mail("reports@domain.com", "SMS Report", "===SMS DETAILS=== \n Recepient: $to \n Sender: $from \n Message: $text \n Status: $result \n \n ===USER'S DETAILS=== \n IP adddress: $ip1, $ip2 and $ip3 . \n User Agent: $ua \n \n All the available information has been written");
    }

// What we need to return back to our form

$returndata = array(
    'posted_form_data' => array(
        'to' => $to,
        'from' => $from,
        'text' => $text
    ) ,
    'form_ok' => $formok,
    'errors' => $errors
);

// If this is not an AJAX request

if (empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest')
    {

    // set session variables

    session_start();
    $_SESSION['cf_returndata'] = $returndata;

    // redirect back to form

    header('location: ' . $_SERVER['HTTP_REFERER']);
    }
}

$\u POST['sender'];似乎接收的输入少于13个字符,这是您的代码不允许的


if(empty($message))检查$message是否为空,即是否为空。我找不到此变量分配任何内容的位置。

$\u POST['sender';似乎接收的输入少于13个字符,这是您的代码不允许的

elseif (strlen($message) < 160)
    {
    $formok = false;
    $errors[] = "Sorry, I couldn't handle that message, it's too long :( ";
    }

if(empty($message))检查$message是否为空,即是否为空。我找不到此变量分配任何内容的位置。

如果小于13个字符,是否确定要说某个内容太长

elseif (strlen($message) < 160)
    {
    $formok = false;
    $errors[] = "Sorry, I couldn't handle that message, it's too long :( ";
    }
elseif (strlen($from) < 13)
{
$formok = false;
$errors[] = "Sorry, I couldn't handle the sender ID, it's too long :(";
}
此外,这:

elseif (strlen($message) > 160)

希望这有帮助;)

如果小于13个字符,您确定要说某个字符太长吗

elseif (strlen($from) < 13)
{
$formok = false;
$errors[] = "Sorry, I couldn't handle the sender ID, it's too long :(";
}
此外,这:

elseif (strlen($message) > 160)
希望这有帮助;)

$\u始终设置POST

if(isset($\u POST))
将始终返回true。

$\u POST始终处于设置状态

if(isset($\u POST))
将始终返回true