2016-04-22 57 views
0

我在Linux Mint系統上安裝了Apache2服務器以進行一些Web開發。我有一個代碼,其中有<pre>標籤中的文字。通過將所有文本轉移到編輯頁面<textarea>,php代碼創建鏈接以編輯文本。增加URI長度限制或更改傳輸大文本的代碼

文本在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>"; 
    } 

這是網頁,文本傳輸到(editstory.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> 

回答

0

我無法弄清楚如何改變我的代碼,所以我增加了URI長度了。

0

有應該沒有理由篡改URI長度。

您應該將故事文本數據作爲HTTP POST消息正文發送,並且提交可能位於HTML表單元素內。

W3 PHP5 Form Handling