ببین من این توضیحات را برات میگم به شرطی که کامل بخونیشون:
اول یک صفحه به اسم index.php فرض میکنیم داری و ساختارش به صورت زیر هستش:
PHP:
<?
///////////////////////////////////////////////////////////////////////////////////////
// In the name of God //
// This portal is a private portal And it was writen by Mohsen Davari //
// Please do not change its copyright //
// I hope that you enjoy using my portal //
// If you have any problem contact me with this email => [email protected] //
// Thank`s a lot //
// Bye //
///////////////////////////////////////////////////////////////////////////////////////
// include inc.php for keeping your session in correct way //]
require("inc.php");
//conect to mysql and get the username//
//mysql host name//
$DBHOST = "localhost";
//database username//
$DBUSER = "";
//database password//
$DBPASS = "";
//database name//
$DBNAME = "";
//Connect to mysql//
mysql_connect($DBHOST, $DBUSER, $DBPASS) or die(mysql_error());
//Connect to database//
mysql_select_db($DBNAME) or die(mysql_error());
if(!isset($_SESSION['username'])){
if(isset($_POST['username'])){
//conect to your table for example users table//
$result =mysql_query("SELECT * FROM users WHERE username='{$_post['username']}'") or die(mysql_error());
$row = mysql_fetch_array( $result );
// creat some session if this username exit//
if (mysql_num_rows($result) > 0) {
$_SESSION['username'] = $_POST['username'];
}else{
print'this username does not exit';
}
}
}
//here you can put your other php code//
?>
دیگه این از توضیحات فایل index.php فقط یه توضیح داره که قبلا با یک فرم تو باید یوزرنیم را برای این فایل بفرستی.
حالا بریم سراغ فایل inc.php که وظیفه ی حمل این سشن را داره:
PHP:
<?
///////////////////////////////////////////////////////////////////////////////////////
// In the name of God //
// This portal is a private portal And it was writen by Mohsen Davari //
// Please do not change its copyright //
// I hope that you enjoy using my portal //
// If you have any problem contact me with this email => [email protected] //
// Thank`s a lot //
// Bye //
///////////////////////////////////////////////////////////////////////////////////////
//keep the session in safe and correct way//
session_start();
?>
حالا هر صفحه ای که بخواهی توی سایتت بزاری باید این فایل inc.php را شامل بشه و ساختارش شکل فایل زیر باشه:
PHP:
<?
///////////////////////////////////////////////////////////////////////////////////////
// In the name of God //
// This portal is a private portal And it was writen by Mohsen Davari //
// Please do not change its copyright //
// I hope that you enjoy using my portal //
// If you have any problem contact me with this email => [email protected] //
// Thank`s a lot //
// Bye //
///////////////////////////////////////////////////////////////////////////////////////
//keep the session in safe and correct way//
require("inc.php");
//you can put your other php code here //
?>
دیگه از این توضیح کامل تر نمیتونم بدم