$_POST['username']接收到的数据怎么填入到单引号中?

雪人兄弟连 2019-08-16 11:37:11
<?php
$username= $_POST['username'];

$urls = array(

'填入这里',

);
$api = 'http://1.1.1.1';
$ch = curl_init();
$options = array(
CURLOPT_URL => $api,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => implode("\n", $urls),
CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
echo $result;
?>
...全文
316 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
雪人兄弟连 2019-08-20
  • 打赏
  • 举报
回复
引用 5 楼 limit81995 的回复:
其他说的都已经变味了。应该不是楼主要的结果。 $urls = array( "'".$a."'", ); //$a 是你想添加的东西。
我用html表单提交网址依然显示无效, 源代码是这样:
<?php

$urls = array(

       'http://www.xxx.com/xxx',
);
$api = 'http://1.1.1.1';
$ch = curl_init();
$options =  array(
    CURLOPT_URL => $api,
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POSTFIELDS => implode("\n", $urls),
    CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
echo $result;
?>
直接提交就可以执行成功,但是使用表单传递过去url就不行。望指点
雪人兄弟连 2019-08-20
  • 打赏
  • 举报
回复
引用 5 楼 limit81995 的回复:
其他说的都已经变味了。应该不是楼主要的结果。 $urls = array( "'".$a."'", ); //$a 是你想添加的东西。
为什么反馈的是空的,无效?
雪人兄弟连 2019-08-20
  • 打赏
  • 举报
回复
引用 3 楼 conqweal 的回复:



<?php
$username= $_POST['username'];

$urls = array(

       'username'=>$username,
    
);
$api = 'http://1.1.1.1';
$ch = curl_init();
$options =  array(
    CURLOPT_URL => $api,
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POSTFIELDS => implode("\n", $urls),
    CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
echo $result;
?>


用了你的方法,解决了问题, 谢谢。
mahuatengBC 2019-08-17
  • 打赏
  • 举报
回复
$urls[] = $username; 或者array_push($urls,$username);
雪人兄弟连 2019-08-16
  • 打赏
  • 举报
回复
初学者基础,希望各位大佬帮忙
conqweal 2019-08-16
  • 打赏
  • 举报
回复



<?php
$username= $_POST['username'];

$urls = array(

       'username'=>$username,
    
);
$api = 'http://1.1.1.1';
$ch = curl_init();
$options =  array(
    CURLOPT_URL => $api,
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POSTFIELDS => implode("\n", $urls),
    CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
echo $result;
?>


雪人兄弟连 2019-08-16
  • 打赏
  • 举报
回复
别沉了

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧