المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : التحقق من الأعضاء بالكوكيز بشكل مُأمن (كلاس)



linnou
11-01-2013, بتوقيت غرينيتش 03:49 PM
http://www.dzbatna.com/images/icons/iconrote.gif ط§ظ„طھط*ظ‚ظ‚ ظ…ظ† ط§ظ„ط£ط¹ط¶ط§ط، ط¨ط§ظ„ظƒظˆظƒظٹط² ط¨ط´ظƒظ„ ظ…ظڈط£ظ…ظ† (ظƒظ„ط§ط³) (http://www.dzbatna.com/t1666213/)


السلام عليكم ورحمة الله

عيد مبارك سعيد وكل عام وأنتم بخير http://www.dzbatna.com/images/smilies/bigsmile.gif

الكلاس هذا سبق ووضعت درس مفصلا لكيفية التعامل مع فكرته

والآن ظهر أنه كلاس سوف يكون سهلا في الإستخدام والتعامل

المعذرة إن كان فيه أخطاء

الكلاس:

رمز PHP:

<code style="white-space:nowrap"> <code>
<?php
/**
* @author Mohammed Cherkaoui
* @link www.cherkaoui-php.com
* @copyright 2014
*/



class userChecker
{

/**
* Users table name
*
* @private string
*/
private $tableName;


/**
* Cookies names



*
* @private array
*/

private $cookiesNames = array('Username' => 'cookie_username','Password' => 'cookie_password');


/**
* Table columns names
*
* @private array
*/

private $columnsNames = array('Username' => 'column_username', 'Password' => 'column_password');

/**
* Array of the navigator rows
*
* @private array
*/

private $userinfo = array();

/**
* Language
*
* @private array
*/

// زائر = visitor > for the non-arabs ;)

private $Lang = array('visitor' => 'زائر');


/**
*
* Class constructor
*
*/

function _construct($tableName = 'users', $columnsNames = array('Username' => 'column_username', 'Password' => 'column_password'), $cookiesNames = array('Username' => 'cookie_username','Password' => 'cookie_password'))
{
$this->tableName = $tableName;
$this->columnsNames = $columnsNames;
$this->cookiesNames = $cookiesNames;
}

/**
*
* Start checking the navigator
*
*/

function Check()
{
$Check = $this->doCheck($this->getCookies());

if($Check == 0)
{
$this->userinfo = array($this->columnsNames&#91;'Username'&#93; = $this->Lang&#91;'visitor'&#93;, 'usergroup' => 0);

} else
{
$this->userinfo = $Check;
$this->userinfo&#91;'usergroup'&#93; = isset($Check&#91;'usergroup'&#93;) ? $Check&#91;'usergroup'&#93; : 1;
}
}


/**
*
* Getting cookies according to the names in $cookiesNames var
*
*/


function getCookies()
{
return array('Username' => $_COOKIE&#91;$this->cookiesNames&#91;'Username'&#93;&#93;, 'Password' => $_COOKIE&#91;$this->cookiesNames&#91;'Password'&#93;&#93;);

}



function doCheck()
{
if(empty($Cookies&#91;'Username'&#93;) || empty($Cookies&#91;'password'&#93;))
{
return 0;
} else
{
$userQuery = mysql_query("select * from ".$this->tableName." where
".$this->$columnsNames&#91;'Username'&#93;." = '".mysql_real_escape_string($Cookies&#91;'username'&#93;)."'
and ".$this->$columnsNames&#91;'Password'&#93;." = '".mysql_real_escape_string($Cookies&#91;'Password'&#93;)."'
limit 1
") or die(mysql_error());
if(mysql_num_rows($userQuery) == 0)
{
return 0;
} else
{
return mysql_fetch_assoc($userQuery);
}
}
}



}

?> </code> </code>


لنشرح طريقة طريقة الإستخدام

هي سهلة جدا ، لكن يتوجب عليك التركيز في الأول فقط

لاحظ التالي:

رمز PHP:

<code style="white-space:nowrap"> <code> $User = new userChecker('users', array('Username' => 'column_username', 'Password' => 'column_password'), array('Username' => 'cookie_username','Password' => 'cookie_password'));
</code> </code>


البارميتر الأول : إسم الجدول

البراميتر الثاني : مصفوفة تحتوي على حقل الإسم وكلمة المرور في جدول الأعضاء
غير column_username بإسم حقل الإسم
و غير ايضا column_password بإسم حقل كلمة المرور

البارميتر الثالث:

نفس فكرة السابق إلا أنه حول الكوكيز

غير cookie_username بإسم كعكة الإسم
وغير cookie_password بإسم كعكة كلمة المرور


مثال كامل على الإستخدام:

رمز PHP:

<code style="white-space:nowrap"> <code> $User = new userChecker('users', array('Username' => 'column_username', 'Password' => 'column_password'), array('Username' => 'cookie_username','Password' => 'cookie_password'));
if($User->userinfo('usergroup') == 0)
{
echo 'Hey , You Are Just A Visitor !';
} else // so userinfo('usergroup') > 0 or = 1
{
echo 'You Are A member !';
}
echo '<br />';
echo $User->userinfo('username'); // Let's try to print the name of the user
</code> </code>


ملاحظة: الكلاس برمجته على السريع ولم أجربه جيدا والمعذرة في حالة وجود أخطاء


تحياتي





ألعاب الأندرويد مجانا و حصريا (http://www.apotox.info/forum)




https://fbcdn-sphotos-d-a.akamaihd.net/hphotos-ak-ash4/482113_236967293114455_1193518507_n.png (http://www.dzbatna.com)
©المشاركات المنشورة تعبر عن وجهة نظر صاحبها فقط، ولا تُعبّر بأي شكل من الأشكال عن وجهة نظر إدارة المنتدى (http://www.dzbatna.com)©

استعمل مربع البحث في الاسفل لمزيد من المواضيع


سريع للبحث عن مواضيع في المنتدى