php – 类的对象..无法转换为字符串

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 类的对象..无法转换为字符串脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我完成了我的第一堂课,但我无法将对象转换回字符串.
class Cryption
{
    VAR $data;
    var $salt;

function __construct($data,$salt)
{
    $this->data = $data;
    $this->salt = $salt;
}

function sha512()
{
    $sodium = 'Na';
    return hash_hmac("sha512",$this->data . $this->salt,$sodium);
}

function encrypt()
{
    $salt = substr(sha512(($this->key),'brownies'),30);
    return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256,$salt,$this->data,MCRYPT_MODE_CBC,md5($salt)));
}

当我使用它时:

$password = new Cryption(MysqL_real_escaPE_string(trim($_POST['password'])),'pepper');
$password->sha512();

它说’PHP catchable致命错误:类Cryption的对象无法转换为字符串’

我真的不知道怎么把它重新变成一个字符串.愿有人请帮帮我吗?

谢谢.

编辑:

<?PHP
require("con@L_@R_360_2621@_5@.PHP");
include("includes/cryption/cryption.PHP");

$username = MysqL_real_escape_string(trim($_POST['username']));
$password = new Cryption(MysqL_real_escape_string(trim($_POST['password'])),'pepper'); //use a different salt next time such as a special salt for each user
$password->sha512();

$result = MysqL_query("SELECT * From `administrators` WHERE username='$username' and password='$password'");
$row = MysqL_fetch_row($result);
$count = MysqL_num_rows($result);

if ($count == 1) {
    if (isset($_POST['remember'])) {
        session_start();
        $_SESSION['user'] = array(
            'id' => $row[0],'username' => $row[1],'password' => $row[2]
        );
        $userid = new Cryption($_SESSION['user']['id'],'kkFishing');
        $session = new Cryption($_SESSION['user']['username'],'kkfishing');
        $validated = new Cryption($_SESSION['user']['password'],'kkfishing');

        setcookie("uniqueid",$userid->encrypt(),time() + 60 * 60 * 24 * 100,"/"); //100 days
        setcookie("kksessionid",$session->encrypt(),"/");
        setcookie("kkuserid",$validated->encrypt(),"/");//disguised cookie name
    }
    session_start();
    $_SESSION['authenticated'] = $row[0];
    echo '1'; //true
    exIT;
}
else
{
    echo '0'; //false
    exit;
}
?>
看看这一行:
$password->sha512();

$result = MysqL_query("SELECT * From `administrators` WHERE username='$username' and password='$password'");

$password是一个对象.它应该是:

$pw = $password->sha512();

$result = MysqL_query("SELECT * FROM `administrators` WHERE username='$username' and password='$pw'");

脚本宝典总结

以上是脚本宝典为你收集整理的php – 类的对象..无法转换为字符串全部内容,希望文章能够帮你解决php – 类的对象..无法转换为字符串所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。