:PHP代碼排錯

來源:互聯網
上載者:User
為什麼PHP代碼(資料庫+外鏈)不能下載?


原始碼 dl_func.php
-------------------------------------------------------
function dl_dbconnect(){

$dl_in=0;

//開啟 MySQL 伺服器串連
$dl_in=mysql_connect("localhost:3306","a1006191543","密碼沒錯");

//選擇一個資料庫
mysql_select_db("a1006191543",$dl_in);
return $dl_in;
}
?>
-------------------------------------------------------


原始碼 filedown.php
-------------------------------------------------------
require_once("dl_func.php");
$dl_in=dl_dbconnect();

$strQuery="select url from dl_file where id='$id'"; //定義查詢規則
$dl_res=mysql_query($strQuery,$dl_in); //返回id送到$dl_res
$arrfile=mysql_fetch_array($dl_res); //根據id返回數組到$arrfile


$arr_temp=split("/",$arrfile[url]); //將字串依指定的規則分開
$filename=$arr_temp[sizeof($arr_temp)-1]; //sizeof: 獲知數組的大小

$strQuery="update dl_file set count=count+1 where id='$id'";
mysql_query($strQuery,$dl_in);

header("Content-type: application/file");
header("Content-Disposition: attachment; filename=$filename");
header("location:$arrfile[url]");

mysql_close($dl_in);
?>
-------------------------------------------------------



資料庫表"dl_file"結構:

CREATE TABLE dl_file (
id varchar(6),
name varchar(50),
url varchar(200),
count bigint(10)
);



id name url count
-------------------------------------------------------
A001 StellaX http://www.last.com/stella.RAR 0
A002 Z26 http://www.mey.com/Z26.ZIP 0
A003 飛機空戰 http://www.piogame.com/River.bin 0
B012 滑板 http://www.computer.com/Skate.bin 0
B013 藍精靈 http://www.computer.com/Catle.bin 0
D064 史努比 http://www.AKuter.com/Snoopy.bin 0



早先在購買的空間裡,運行正常。

為何在現在的空間裡,也是這2個程式(換了資料庫使用者名稱、密碼),報錯?

調用形式:http://www.******.com/filedown.php?id=A001

IE報錯資訊:
“此錯誤(HTTP 403 禁止)意味著 Internet Explorer 可以串連到該網站,但是沒有查看該網頁的許可權。”



回複討論(解決方案)

先把header注釋掉。echo url看看是否正確

已找到故障點: filedown.php
$strQuery="select url from dl_file where id= '$id'"; //定義查詢規則
改為固定參數後:
$strQuery="select url from dl_file where id= 'A001'"; //定義查詢規則
外鏈正常

但是,如何改正帶參運行?帶參調用形式如下:
http://www.*****.com/down/filedown.php?id=A001

$id = isset($_GET['id']) ? $_GET['id'] : 'A001';
$strQuery="select url from dl_file where id='$id'";

$id如果為空白,你沒有加處理吧。

if(!$id){
exit();
}

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.