簡體   English   中英

加密的字符串與數據庫字符串不匹配

[英]encrypted string does'n't matching with db string

我從我正在解碼的查詢字符串中加密了字符串,解碼后我試圖與數據庫字符串匹配,但這不起作用。這是我的代碼

<?php
require_once("db.php");
$id="";
$emailrole="";
if($_GET){
    if(isset($_GET['id'])){
    $id = base64_decode($_GET['id']);
    $query = "select * from sfrole where email like('{$id}') LIMIT 1";
    $qryy = mysql_query($query);
    $cnt = mysql_num_rows($qryy);
    if($cnt > 0){
        $emailrole = mysql_fetch_array($qryy);
    }else{
        exit();
    }
    }else{
        exit();
    }
}else{
    exit();
}
?>

如果這樣使用

$query = "select * from sfrole where email like('malik.adeel@shakarganj.com.pk') LIMIT 1";

然后它可以工作,如果從變量中使用它則不返回任何東西,請幫助

更新資料

我正在像這樣在C#中使用PHP加密字符串

Convert.ToBase64String(Encoding.Unicode.GetBytes(emailid))

您需要先對字符串進行轉義,然后才能在查詢中運行它。

http://fr2.php.net/function.mysql-real-escape-string.php

<?php
require_once("db.php");
$id="";
$emailrole="";
if($_GET){
    if(isset($_GET['id'])){
    $id = base64_decode($_GET['id']);
    $query = "SELECT * FROM sfrole WHERE email LIKE '" . mysql_real_escape_string($id) . "' LIMIT 1";
    $qryy = mysql_query($query);
    $cnt = mysql_num_rows($qryy);
    if($cnt > 0){
        $emailrole = mysql_fetch_array($qryy);
    }else{
        exit();
    }
    }else{
        exit();
    }
}else{
    exit();
}
?>

試試這個查詢:

select * from sfrole where email = '$id' LIMIT 1

由於什么原因,您使用花括號“ {$ id}”? 我認為,如果您想進行加密,最好使用md5,但對電子郵件進行加密不是很好。 想象一下,您應該向用戶發送電子郵件,但是在發送之前,您應該對它們解密,否則將無法使用並且性能會降低。

更新:

抱歉,現在我知道您沒有將其保存在數據庫的base64中:-)嘗試比較輸入值和數據庫值以了解會發生什么。

您選擇的查詢不正確。請進行更改。 您還可以通過在查詢前使用echo來檢查查詢。 你應該用這個

$query="select * from sfrole where id='$id' and email LIKE 'example@gmail.com'  LIMIT 1"; 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM