나는 SEO 친화적 인 사이트를 만들려고합니다. URL에 product.php?id=4
과 같은 ID가 표시되기 때문에 페이지가 작동하지만 product_name
으로 바꾸려면 여기를 클릭하십시오. 그러나이 값에 공백이 포함될 수 있으므로 URL은 product.php?product_name=fence%20panel
처럼 보이지만이 때문에 작동하지 않습니다. 이 GET 변수를 사용하여 데이터베이스에서 제품 세부 사항을 조회합니다.이 때 GET 변수는 한 단어이므로 제품을 찾을 수 없습니다. 그래서 내가 필요하다고 생각하는 것은 하이픈을 추가하는 변수이므로 product.php?product_name=fence-panel
이 하이픈을 다시 공백으로 변경하는 변수입니다. 내가 rawurlencode()
및 rawurldecode()
사용공백을 URL의 하이픈으로 바꿉니다.
if(isset($_GET['id'])){
$id = $_GET['id'];
//Get the product if exists
//if no product then give a message
$sql = mysqli_query($myNewConnection, "SELECT * FROM products WHERE id='$id' LIMIT 1");
$productCount = mysqli_num_rows($sql);
if ($productCount > 0) {
//get product details
while($row = mysqli_fetch_array($sql)){
$product_name = $row["product_name"];
$price = $row["price"];
$details = $row["details"];
$category = $row["category"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
$_SESSION['product_price_array'] = $price;
}
} else{
echo "No Product in the system";
exit();
}
이것은 해커에게 호의적입니다. –
@marabutt는 자세히 설명해 주시겠습니까? – jhetheringt7
은 SQL 인젝션에 열려 있습니다 –