donglu8344812 2013-08-28 11:34
浏览 8
已采纳

访问POST数据

I'm very new to PHP but have a good understanding of C,

When I want to access some post data on an API i'm creating in PHP I use:

 $_POST['date_set']

to fetch a value being passed for date - This all works perfectly, however I read I should be fetching it like this:

$date_set = trim(urldecode($_POST['date_set']));

This always returns a 00:00:00 value for the date after it's stored in my DB.

When I access directly using $_POST['date_set'] I get whatever value was posted, for example: 2013-08-28 10:31:03

Can someone tell me what I'm messing up?

  • 写回答

4条回答 默认 最新

  • douzizang7783 2013-08-28 11:36
    关注

    You only run urldecode over data is URL encoded. PHP will have decoded it before populating $_POST, so you certainly shouldn't be using that. (You might have to if you are dealing with double-encoded data, but the right solution there should be to not double encode the data).

    trim removes leading and trailing white-space. It is useful if you have a free form input in which rogue spaces might be typed. You will need to do further sanity checking afterwards.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致