2011-11-18 124 views
2

我提交表單,像這樣:jQuery Mobile的 - 表單提交 - 加載頁面時出錯

<form action="userlogin.html" method="get" name="log_form" onsubmit="return form_val();"> 

這是所有好,然後它產生的cookie,如果日誌中正確的如下數據:

if ($email){ // 111 
    require '/php/lib/dbconnect.inc'; 
    $email=strtolower($email); 
    $password=strtolower($password); 
    $result = mysql_query("SELECT name from users where (username = '$email' AND password = '$password')",$db); 
    if(!$result) { echo mysql_error(); exit; } // debug 
    $item = mysql_fetch_row($result); 
    $result_userid = mysql_query("SELECT user_id from users where (username = '$username' AND password = '$password')",$db); 
    if(!$result_userid) { echo mysql_error(); exit; } // debug 
    $item_userid = mysql_fetch_row($result_userid); 
    if ('0'==$item[0]){ // 33 
    $error .= "You typed the wrong email address or password, please check the information entered.<br><br><br>"; 
    } // close 33 
    else { // 44 
    require '/php/lib/setup.inc'; 
    $user = Encrypt_data ($item_userid[0]); 
    setcookie("user_cook", "$user", 0); 
    header("Location: /en/"); 
    } // close 44 
    } // close 111 

但是,我總是得到「錯誤加載頁面」,無論數據輸入是否正確,因此有些事情是不正確的,但是什麼?

另外,我還嘗試添加我的頭包括文件到該評估數據是否正確,其正常工作,但隨後我當然不能用header("Location: /en/");

所以我想澄清之前,等於是經過jQuery Mobile的標記,這一切工作正常和形式傳送數據,但它好像jQuery的需要的東西會看看其他數據...以下工作之前:

if ($email){ // 111 
    include '/home/twovo77/1NTJ3EJZ/php/nav/mobile_header.inc'; 
    // require '/home/twovo77/1NTJ3EJZ/php/lib/dbconnect.inc'; 
    $email=strtolower($email); 
    $password=strtolower($password); 

,但沒有很好的作爲傳遞到標題

mobile_header.inc是:

<? 
require '/php/lib/setup.inc'; 
require '/php/lib/dbconnect.inc'; ?> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html> 

<head> 
<meta charset="utf-8"> 
<meta name="viewport" content='width=device-width, initial-scale=1.0, maximum-  scale=1.0, min-width=321px'> 
<link rel="stylesheet" href="mobile.css" /> 

<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script> 
<script src="http://code.jquery.com/mobile/1.0rc2/jquery.mobile-.0rc2.min.js"> 
</script> 

</head> 

<body> 

<div data-role="page" id="foo" data-title="<? echo $page_title; ?>"> 

<a href="index.html"><div data-role="header" data-theme="c" style="height:50px; padding:3px;"><img src="/images/logo2.png"></div></a><!-- /header --> 

<? echo $header_image; ?> 

<div data-role="content"><div class="inner"> 

那麼,有沒有在那裏的一些標記,必須要通過,否則你會得到錯誤載入頁面

,或者更重要的是,我可以繞過這一點的同時我執行我的日誌代碼然後回到它...如果是這樣,怎麼樣?

回答

1

嘗試使用表單操作的絕對URL(我還沒有弄明白,但基本元素似乎與jQuery Mobile有點古怪)。當我得到這個錯誤時,我看着Firebug來查看請求的執行位置,通常這是與當前頁面和操作位置相關的問題。例如,如果你從根目錄(「/」)開始,從「/ gallery /」目錄中抓取一個頁面,該目錄與「/ gallery /」目錄中的另一個文件具有相對URL,那麼一旦它被拉出到DOM(在「/」級別),任何相對URL都不會匹配。

在一個側面說明,彷彿你正在查詢,這使得注入攻擊可能的數據庫之前逃脫你的數據不會出現:

變化:

"SELECT name from users where (username = '$email' AND password = '$password')" 

而且

"SELECT user_id from users where (username = '$username' AND password = '$password')" 

收件人:

"SELECT name from users where (username = '" . mysql_real_escape_string($email) . "' AND password = '" . mysql_real_escape_string($password) . "')" 

而且

"SELECT user_id from users where (username = '" . mysql_real_escape_string($username) . "' AND password = '" . mysql_real_escape_string($password) . "')" 

否則有人能進入像用戶名:

$username = "' OR 'x'='x"; 

,讓您的查詢看起來像這樣(和解決爲true):

"SELECT name from users where (username = '' OR 'x'='x' AND password = '$password')" 

這裏是PHP mysql_real_escape_string的文檔:http://php.net/mysql_real_escape_string

+0

已更新的問題 –