简体   繁体   中英

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; 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.

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; what's the best way to send a long string in PHP POST?

Thanks in advance for your help, i'm not too savvy with PHP.

Edit: Table config: 在此处输入图片说明

Edit2: Row anomaly with long string > 512 chars: 在此处输入图片说明

Edit3: here's my PHP script, if it helps:

<?
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. 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.

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. See more: What is the maximum possible length of a query string?

Answer 2 You can send your string like simple varible ($_POST). Check only settings for max vals of inputing/exectuting in php.ini .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM