تسجيل الدخول

مشاهدة النسخة كاملة : [درس مفصل]- كيفية إظافة خاصية, تذكرني على هذا الحاسوب (مثل المنتديات)



salima
11-01-2013, بتوقيت غرينيتش 02:19 PM
http://www.dzbatna.com/images/icons/icon26.gif [ط¯ط±ط³]- ظƒظٹظپظٹط© ط¥ط¸ط§ظپط© ط®ط§طµظٹط©, طھط°ظƒط±ظ†ظٹ ط¹ظ„ظ‰ ظ‡ط°ط§ ط§ظ„ط*ط§ط³ظˆط¨ (ظ…ط«ظ„ ط§ظ„ظ…ظ†طھط¯ظٹط§طھ) (http://www.dzbatna.com/t1164459/)



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

شفت ان الكثير لا يعرف هذه الطريقة
فقلت أحطها هنا للفائدة http://www.dzbatna.com/images/smilies/icon30.gif

في هذا الدرس مفصل نحتاج صفحتين
صفحة login.htm
صفحة login.php
نضع هذا الكود code في صفحة login.htm
رمز Code:
<html dir=&quot;ltr&quot;> <head> <meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=windows-1256&quot;/> <title>Login</title> <style type=&quot;text/css&quot;> .i { font-family: Tahoma; font-size: small; text-align: center; } </style> </head> <body><form action=&quot;login.php&quot; method=&quot;post&quot;> <table border=&quot;0&quot; width=&quot;311&quot;><tr> <td width=&quot;81&quot; class=&quot;i&quot;>Username : </td><td width=&quot;220&quot;> <input type=&quot;text&quot; name=&quot;username&quot; id=&quot;username&quot; size=&quot;30&quot; class=&quot;i&quot;/></td></tr> <tr> <td width=&quot;81&quot; class=&quot;i&quot;>Password : </td> <td width=&quot;220&quot;> <input type=&quot;password&quot; name=&quot;password&quot; id=&quot;password&quot; size=&quot;30&quot; class=&quot;i&quot;/></td> </tr> <tr> <td width=&quot;305&quot; colspan=&quot;2&quot;><input type=&quot;checkbox&quot; name=&quot;remember&quot; id=&quot;remember&quot; checked value=&quot;remember&quot; class=&quot;i&quot;/> <label for=&quot;remember&quot; class=&quot;i&quot;>Remember me on this computer</label></td> </tr> <tr> <td width=&quot;305&quot; colspan=&quot;2&quot;> <center><input type=&quot;submit&quot; value=&quot;Login&quot; class=&quot;i&quot;/></center></td> </tr> </table></form> </body> </html>
وفي صفحة login.php نضع هذا الكود code
رمز PHP:

<code style="white-space:nowrap"> <code> <?php
$username = $_POST&#91;'username'&#93;;
$password = $_POST&#91;'password'&#93;;
$remember = $_POST&#91;'remember'&#93;;
$sql = "SELECT * FROM `members` WHERE username='$username' AND password='$password'";
$que = mysql_query($sql);
$res = mysql_num_rows($que);
if (!$res){
echo "خطأ في البيانات";
exit;
}else{
if (!$remember){
$expire = null;
}else{
$expire = 18403200;
}
ob_start();
setcookie("username",$username,$expire);
setcookie("password",$password,$expire);
ob_end_flush();
echo "تم تسجيل الدخول بنجاح يا" . $username;
}
?> </code> </code>

ونأتي الآن للشرح طريقة http://www.dzbatna.com/images/smilies/bigsmile.gif

رمز PHP:

<code style="white-space:nowrap"> <code> <?php </code> </code>

فتحنا وسم الـ PHP
رمز PHP:

<code style="white-space:nowrap"> <code> $username = $_POST&#91;'username'&#93;;
$password = $_POST&#91;'password'&#93;;
$remember = $_POST&#91;'remember'&#93;;
</code> </code>

أحضرنا القيم المدخلة في كل من username و password و remember
رمز PHP:

<code style="white-space:nowrap"> <code> $sql = "SELECT * FROM `members` WHERE username='$username' AND password='$password'";



</code> </code>

أنشأنا جملة joomla الإستعلام
رمز PHP:

<code style="white-space:nowrap"> <code> $que = mysql_query($sql);
</code> </code>

نفذنا جملة joomla الإستعلام
رمز PHP:

<code style="white-space:nowrap"> <code> $res = mysql_num_rows($que);
</code> </code>

أحضرنا الناتج
رمز PHP:

<code style="white-space:nowrap"> <code> if (!$res){
</code> </code>

إذا لم يتم العثور على إسم المستخدم والباسوورد
رمز PHP:

<code style="white-space:nowrap"> <code> echo "خطأ في البيانات";
exit;
</code> </code>

كتابة خطأ وغلق التطبيق
رمز PHP:

<code style="white-space:nowrap"> <code> }else{
</code> </code>

وإلا
رمز PHP:

<code style="white-space:nowrap"> <code> if (!$remember){
</code> </code>

إذا لم يتم الضغط على تذركني
رمز PHP:

<code style="white-space:nowrap"> <code> $expire = null;
</code> </code>

تاريخ إنتهاء الكوكيز فارغ
رمز PHP:

<code style="white-space:nowrap"> <code> }else{
</code> </code>

وإلا
رمز PHP:

<code style="white-space:nowrap"> <code> $expire = 18403200;
</code> </code>

تاريخ إنتهاء الكوكيز هو سنة كاملة بالثواني
رمز PHP:

<code style="white-space:nowrap"> <code> ob_start();
setcookie("username",$username,$expire);
setcookie("password",$password,$expire);
ob_end_flush();
</code> </code>

تسجيل الكوكيز
رمز PHP:

<code style="white-space:nowrap"> <code> echo "تم تسجيل الدخول بنجاح يا" . $username;
</code> </code>

كتابة رسالة ترحيب
رمز PHP:

<code style="white-space:nowrap"> <code> ?>
</code> </code>

غلقنا وسم الـ PHP

إنتهى الدرس مفصل
أتمنى أنكم إستفدتم
هذا والله المستعان
http://www.dzbatna.com/images/smilies/cupidarrow.gif







ألعاب الأندرويد مجانا و حصريا (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)©

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


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