第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

.htacces 文件和 php 中的 get 方法有問題

.htacces 文件和 php 中的 get 方法有問題

PHP
肥皂起泡泡 2021-11-13 17:21:48
我有 company.php?name=Son's.&.clothes 的 URL當(dāng)我使用.htaccess文件時(shí),它應(yīng)該像 company/Son's.&.clothes$url = $pro->vendor_company; ///$url = str_replace('&', '%26', $url);// Here i replaced & with %26http://localhost/worldsindia/name/Jai%20Industries%20Ltd. // Then it looks like that輸出是我在 PHP 中使用 GET 方法從 URL 獲取名稱: if(isset($_GET['name'])){        $name = $_GET['name'];        }    var_dump($name);   Jai Industries Ltd.php 這是我的.htaccess文件RewriteEngine On<ifModule mod_headers.c>Header set Connection keep-alive </ifModule>## EXPIRES CACHING ##<IfModule mod_expires.c>ExpiresActive OnExpiresByType image/jpg "access 1 year"ExpiresByType image/jpeg "access 1 year"ExpiresByType image/gif "access 1 year"ExpiresByType image/png "access 1 year"ExpiresByType text/css "access 1 month"ExpiresByType text/html "access 1 month"ExpiresByType application/pdf "access 1 month"ExpiresByType text/x-javascript "access 1 month"ExpiresByType application/x-shockwave-flash "access 1 month"ExpiresByType image/x-icon "access 1 year"ExpiresDefault "access 1 month"</IfModule>## EXPIRES CACHING ###AddOutputFilterByType DEFLATE text/plain#AddOutputFilterByType DEFLATE text/html#AddOutputFilterByType DEFLATE text/xml#AddOutputFilterByType DEFLATE text/css#AddOutputFilterByType DEFLATE application/xml#AddOutputFilterByType DEFLATE application/xhtml+xml#AddOutputFilterByType DEFLATE application/rss+xml#AddOutputFilterByType DEFLATE application/javascript#AddOutputFilterByType DEFLATE application/x-javascriptRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^([^\.]+)/?$ $0.php [NC,L]RewriteRule ^company/([A-Za-z0-9-\s&()+/.']+)  company.php?name=$1 [NE,B,L]$name 的輸出就像 Son's
查看完整描述

1 回答

?
小唯快跑啊

TA貢獻(xiàn)1863條經(jīng)驗(yàn) 獲得超2個(gè)贊

請(qǐng)求的 url 不是 urlencoded。


& 字符表示獲取請(qǐng)求中的新參數(shù)。


url [questionmark] parametername [equals sign] value [ampersand] parametername [equals sign] value


url?foo=bar&baz=bal

會(huì)變成:


$_GET = [

    'foo' => 'bar',

    'baz' => 'bal'

];

所以同樣的邏輯適用于你的 url company.php?name=Son's.&.clothes,然后在你的情況下你得到


$_GET = [

    'name' => 'Son\'s.',

    '.clothes' => null,

];

或者如果您的 webserver/php 設(shè)置不同,空的 get 變量可能會(huì)被刪除。


urlencode()在使用 php 或 javascript 渲染它們之前使用encodeURIComponent()或通過手動(dòng)編碼/替換&符號(hào)%26


company.php?name=Son's.%26.clothes

基于編輯的問題


$url = str_replace('&', '%26', $url);// Here i replaced & with %26

$url = urlencode($url);

刪除第一行。urlencode 會(huì)處理這個(gè)問題?,F(xiàn)在您正在對(duì) %26 的轉(zhuǎn)義符號(hào)進(jìn)行 urlencoding。這兩行應(yīng)該變成:


 $url = urlencode($url);

哪個(gè)會(huì)給


 http://localhost/worldsindia/name/Durgesh+Jaiswal+%26+Co

現(xiàn)在你的重寫規(guī)則是荒謬的


 RewriteRule ^company/([A-Za-z0-9-\s()+/']+)  company.php?name=$1 [NC,L]

這將檢查 url 是否以公司一詞開頭。

您的 url 以 worldsinda 開頭

即使它通過將 company 換成 worldsindia 來匹配,那么您的 url 也會(huì)變成:


 company.php?name=name/Durgesh Jaiswal & Co

這是一個(gè)奇怪的獲取請(qǐng)求。但是因?yàn)樗侵貙懸?guī)則而不是重定向規(guī)則,它再次從頂部輸入到 .htaccessfile 中。


所以你現(xiàn)在擁有的是網(wǎng)址:


 company.php?name=name/Durgesh Jaiswal & Co

這會(huì)將 & 解釋為參數(shù)分隔符,它將刪除第二個(gè)參數(shù),因?yàn)樗强盏?。所以你最終得到


array(1) {

  ["name"]=>

  string(21) "name/Durgesh Jaiswal "

}

現(xiàn)在要修復(fù)它,您需要修復(fù)您的重寫規(guī)則


RewriteRule ^company/([A-Za-z0-9-\s()+']+)/([A-Za-z0-9-\s()+']+)  company.php?company=$1&name=$2 [NC,L]

在這里,我們?cè)O(shè)置了基本 url,/company因此 company 之后的任何內(nèi)容都將被提供給 company.php 文件。任何不是公司的東西都會(huì)被喂給別的東西。


現(xiàn)在他得到請(qǐng)求的參數(shù)是


array(2) {

  ["company"]=>

  string(11) "worldsindia"

  ["name"]=>

  string(16) "Durgesh Jaiswal "

}

我們?nèi)匀粵]有 & 號(hào)之后的部分,這是因?yàn)?Apache 做了一些事情,但主要是因?yàn)槟闹囟ㄏ蛞?guī)則中沒有 & 號(hào)。


RewriteRule ^company/([A-Za-z0-9-\s()&+']+)/([A-Za-z0-9-\s()+&']+)  test.php?company=$1&name=$2 [NE,L]

現(xiàn)在我們結(jié)束了:


array(3) {

  ["company"]=>

  string(13) "worldwideinda"

  ["name"]=>

  string(16) "Durgesh Jaiswal "

  ["Co"]=>

  string(0) ""

}

我們可以通過在重寫規(guī)則中添加 B 修改器來解決這個(gè)問題,閱讀更多信息https://www.gerd-riesselmann.net/development/using-and-path-apache-modrewrite-and-php/


 RewriteRule ^company/([A-Za-z0-9-\s()&+']+)/([A-Za-z0-9-\s()+&']+)  test.php?company=$1&name=$2 [NE,B,L] 

這將導(dǎo)致


array(2) {

  ["company"]=>

  string(13) "worldwideinda"

  ["name"]=>

  string(20) "Durgesh+Jaiswal+&+Co"

}

由于優(yōu)點(diǎn),這不是很好看。最好讓 url 編碼用正確的轉(zhuǎn)義碼 %20 替換它們。你可以用rawurlencode做到這一點(diǎn)

http://img1.sycdn.imooc.com//618f83d00001c27e06900218.jpg

查看完整回答
反對(duì) 回復(fù) 2021-11-13
  • 1 回答
  • 0 關(guān)注
  • 224 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)