增加URI长度限制或更改传输大文本的代码

Increase URI length limit or change the code for transferring big text

我在linux Mint 系统上安装了Apache2 服务器来做一些网络开发。我有一个代码,其中 <pre> 标记中有一个文本。 php 代码使 link 通过将所有文本传输到编辑页面 <textarea> 来编辑文本。

URI 中的文本传输。好吧,由于 Apache 有 URI 长度限制,我不知道如何传输大量文本。 我搜索并发现有一种方法可以更改此限制,但我找不到它的设置位置。我还读到使用长 URI 不好。

所以,我必须增加 URI 长度限制或更改我的代码。不过,我还没弄清楚怎么做。这是文本所在的页面(story.php,存储在 $s 变量中):

<!DOCTYPE html>
<?php session_start() ?>
<html>
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="main.css">
    <title>The story</title>
    <style>
        #story{border: darkolivegreen; border-style: solid ;border-width: 3px; padding: 10px }
        pre{white-space: pre-wrap}
        span{padding-right: 8px}
    </style>
</head>

<body>
<?php
include "navigation.php";
$id=$_GET['id'];
//ar_dump($id);
$mysql=new mysqli("",databaseuser,databasepassword,database);
$set=$mysql->query("select title,story,creator,dateCreated,identifier from Stories where identifier='$id'");
if( $set==false) echo $mysql->error;
$record=$set->fetch_array();
//var_dump($record);
if($record)
{
    $t=$record['title'];
    //check
    $s=htmlspecialchars_decode($record['story']);
    $c=$record['creator'];
    $time=$record['dateCreated'];
    $storyid=$record['identifier'];
    echo "<h1 id='heading'>$t</h1>";
    echo "<h2>By $c on $time</h2>";
    echo "<pre id='story' on>$s</pre>";
    if(isset($_SESSION[username]))
    $user=$_SESSION[username];

    $q="SELECT class FROM Accounts WHERE identifier='$user'";
    $result=$mysql->query($q);
    $group;
    if($res)
    {
        $group=$result->fetch_array()[0];
    }
    if(($user==$c && $group==users2) or $group==admins or $group==overseers)
    {
        $s=urlencode($s);
        $link='editstory.php?sid='.$storyid.'&text='.$s;
        echo "<a href='$link'>Edit</a>";
        //echo "<button data-storyid='$storyid' data-story='$s' onclick=''>Edit</button> ";
        echo "<button data-storyid='$storyid' onclick='deleteStory(this)'>Delete</button>";
    }

这是文本转入的页面(编辑story.php):

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Editing</title>
    <link rel="stylesheet" href="main.css"
</head>
<body>
<?php
$storyid=$_GET['sid'];
$text=$_GET['text'];
$text=urldecode($text);
echo "<textarea id='text' rows='33' cols='200'>$text</textarea>
        <button data-sid='$storyid' onclick='updatestory(this)'>Save</button>
"
?>
<script>
    function updatestory(button) {
        var sid=button.getAttribute('data-sid')
        var text=document.getElementById('text')
        var value=text.value;
        console.log(text.value)
        var request=new XMLHttpRequest()
        request.onreadystatechange=function () {
            if(request.readyState==4)
            {
                window.location='story.php?id='+sid;
                console.log(request.responseText)
            }
        }
        request.open('POST','updatestory.php',true)
        request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        request.send('sid='+sid+'&text='+value)
    }

</script>
</body>
</html>

没有理由篡改 URI 长度。

您应该将故事文本数据作为 HTTP POST 消息正文发送,并且可以在 HTML 表单元素内提交。

W3 PHP5 Form Handling

我不知道如何更改我的代码,所以我现在增加了 URI 长度。