[英]How do i post a long string into a PHP page?
This question has two parts: 这个问题分为两个部分:
Part I - restriction? 第一部分-限制?
I'm able to store data to my DB with this: 我可以通过以下方式将数据存储到数据库中:
www.mysite.com/myscript.php?testdata=abc123
This works for a short string (eg 'abc123') and the page echos what was written to the DB; 这适用于短字符串(例如'abc123'),并且页面回显写入数据库的内容; however, if the [testdata=] string is longer than 512 chars and i check the database, it shows a row has been added but it's blank and also my echo statement in the script doesn't display the input string.
但是,如果[testdata =]字符串长于512个字符,并且我检查数据库,则表明已添加一行,但该行为空,而且脚本中的echo语句也不会显示输入字符串。
NB I'm on a shared server and have emailed my host to see if it's a restriction. 注意:我在共享服务器上,并通过电子邮件发送给主机,以查看是否有限制。
Part II - best practice? 第二部分-最佳做法?
If i can get past the above hurdle, I want to use a string that's ~15k chars long created in a desktop app that concatenates the [testdata=] string from various parameters; 如果可以克服上述障碍,我想使用一个在桌面应用程序中创建的〜15k字符长的字符串,该字符串将各种参数的[testdata =]字符串连接起来; what's the best way to send a long string in PHP POST?
在PHP POST中发送长字符串的最佳方法是什么?
Thanks in advance for your help, i'm not too savvy with PHP. 在此先感谢您的帮助,我对PHP不太了解。
Edit: Table config: 编辑:表配置:
Edit2: Row anomaly with long string > 512 chars: Edit2:行异常,长字符串> 512个字符:
Edit3: here's my PHP script, if it helps: Edit3:这是我的PHP脚本,如果有帮助的话:
<?
include("connect.php");
$data = $_GET['testdata'];
$result = mysql_query("INSERT INTO test (testdata) VALUES ('$data')");
if ($result) // Check result
{
echo $data;
}
else echo "Error ".$mysqli->error;
mysql_close(); ?>
POST is definitely the method you want to use, and your best bet with that will be with cURL. POST绝对是您要使用的方法,最好的选择是使用cURL。 Something like this should work:
这样的事情应该起作用:
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, "http://www.mysite.com/myscript.php" );
curl_setopt( $ch, CURLOPT_POST, TRUE );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $my_really_long_string );
$data = curl_exec( $ch );
You'll need to modify the above to include additional cURL options as per your environment, but something like this is what you'd be looking for. 您需要根据环境修改以上内容以包含其他cURL选项,但这就是您想要的。
You'll want to make sure that your DB field is long enough to hold the really long string as well. 您将要确保您的数据库字段足够长以容纳真正长的字符串。
Answer 1 Yes, max length of url has restriction. 回答1是的,URL的最大长度有限制。 See more: What is the maximum possible length of a query string?
查看更多: 查询字符串的最大可能长度是多少?
Answer 2 You can send your string like simple varible ($_POST). 答案2您可以像简单变量($ _POST)一样发送字符串。 Check only settings for max vals of inputing/exectuting in
php.ini
. 仅检查
php.ini
中输入/执行的最大值的设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.