English 中文(简体)
请帮助我恢复对我的Sql的数据。
原标题:Please help me to sanitize php data goint to mysql
  • 时间:2010-09-16 07:41:42
  •  标签:
  • php
  • mysql

亲爱的朋友 我的表象是我的q。

<label for="fullname">Fullname</label>
<input type="text" name="fullname" />

<label for="photo">Upload photo</label>
<input name="photo" type="file"/>

和在“基地”组织目标上,我

$fullname = $_POST[ fullname ];

    $uploaddir =  ./uploads/ ;
    //upload file in folder
    $uploadfile = $uploaddir. basename($_FILES[ photo ][ name ]);
    //insert filename in db
    $upload_filename = basename($_FILES[ photo ][ name ]);
    move_uploaded_file($_FILES[ photo ][ tmp_name ], $uploadfile);
    $photo = $upload_filename;

$sql = "INSERT INTO members(fullname,photo) VALUES( $fullname ,  $photo )";
$stmt = $link->query($sql) or die($link->error);
    $stmt->close;

请帮助我,我是在现场利用这一信息。

最佳回答

改用准备发言:

$fullname = $_POST[ fullname ];

    $uploaddir =  ./uploads/ ;
    //upload file in folder
    $uploadfile = $uploaddir. basename($_FILES[ photo ][ name ]);
    //insert filename in db
    $upload_filename = basename($_FILES[ photo ][ name ]);
    move_uploaded_file($_FILES[ photo ][ tmp_name ], $uploadfile);
    $photo = $upload_filename;

$sql = "INSERT INTO members(fullname,photo) VALUES(?, ?)";
$stmt = $link->prepare($sql);
$stmt->bind_param( ss ,$fullname,$photo);
$stmt->execute();

详情见 准备发言。 http://en.wikipedia.org/wiki/SQL_injection”rel=“nofollow noreferer”>SQLjection in

问题回答

在你重新使用<代码>mysqli时,请你回答参数问题。 这一般比试图逃避扼杀::

$q= $mysqli->prepare( INSERT INTO members (fullname, photo) VALUES (?, ?) );
$q->bind_param( ss , $fullname, $photo);
$q->execute();

请注意,将用户-用户-用户-用户-应用文档名称用于文件上载的风险很大。 在其现行代码中,用户可上载.php文档,如果uploads ,则文件夹可上网络服务器,从而使攻击者能够在服务器上操作其选择的任意代码。

其他潜在麻烦的档案名称包括空档、非ASCII和控制特性、>.htaccess在阿帕奇服务器上,以及带有铅/交易狗和空间的档案,或使用一个系统在Windows服务器上保留文档名称。 此外,似乎没有任何保护防止用户上载照片,该照片超越了另一个用户,这似乎很有可能发生事故。

通常最好从随机数目或排位主要钥匙中生成一个档案名称,并增加你想要的延伸(例如<代码>.jpeg)。 宣传用户提供的文件名称比你想象的要困难得多。

请帮助我,我是在现场利用这一信息。

如果接触到非托管用户,我会认真对待网站,直到您确定网站。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...