如何将文本文件的内容作为url参数传递


How do I pass content of a text file as a url parameter

我想将文本文件的内容传递到url。因此,我使用fgets函数逐行读取文件的内容,并将其存储在字符串中,然后将其传递给有问题的url。但由于某种原因,它不起作用。我该如何做到这一点,或者将文本文件的内容作为参数传递到url中。

$handle= fopen("/path/to/file/filename.txt","r");
while(($line=fgets($handle))!==false) {        
    $msisdn=str_replace("'n", " ", $line);
}
$send="http://127.0.0.1:13014/cgi-bin/sendsms?username=tester&password=foobar&text=text&from=shortcode&to=$msisdn&smsc=smsc";
fclose($handle);
   $curl=curl_init();
   curl_setopt($curl,CURLOPT_URL,$send);
   curl_setopt($curl,CURLOPT_RETURNTRANSFER, 1);
   $result=curl_exec($curl);
   curl_close($curl)

编辑:我可以将文件的内容(这是一个数字列表)传递到字符串"$msisdn",但url的回声显示它只选择一个数字。如何将文件的所有内容传递到url。

$handle= fopen("/path/to/file/filename.txt","r");
  while(($line=fgets($handle))!==false){        
     $msisdn=str_replace("'n", " ", $line);
  }
$send="http://127.0.0.1:13014/cgi-bin/sendsms?username=tester&password=foobar&text=text&from=$shortcode.&to=$msisdn&smsc=smsc";
fclose($handle);
header('Location: '.$send);

1st:在URL=>安全问题中从不传输机密数据
第二次:始终验证函数的返回值=>您不能保证文件已成功打开
3rd:您的文件结构是什么?我们应该猜测一下吗
4th:尝试更好的实现,使用类似的东西

$params = array ('username' => $username,
                 'text'     => $text);
$preparedParams = array();
foreach($params as $paramKey => $paramValue) {
   // do control if $paramValue is valid ... log error .. throw something
   $preparedParams[] = $paramKey . '=' . $paramValue ;
}
$urlParams = explode ('&', $preparedParams);
header('Location: ' . YOUR_SERVER:PORT/YOUR_CONTROLLER/ . $urlParams;

我的建议是使用PHP CURL而不是header('Location: ')