# GÓC SÁNG TẠO > Khu vực lập trình > Mã nguồn mở >  Giúp mình phần quản trị trong php

## phuongdtn

```

[COLOR=#000000]mình đang làm một đồ án về web, mình đang làm phần quản trị, mình đã tạo được 2 file index và login, nhưng mình cứ login thì nó lại quay lại login, mà mình nhập đúng tai khoản, bạn nào giúp mình với.đây la file index[php]<?php 


```

[/COLOR]

```

[COLOR=#007700]if([/COLOR][COLOR=#0000BB]$_SESSION[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"login"[/COLOR][COLOR=#007700]]== [/COLOR][COLOR=#0000BB]NULL [/COLOR][COLOR=#007700]or [/COLOR][COLOR=#0000BB]$_SESSION[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"login"[/COLOR][COLOR=#007700]] <> [/COLOR][COLOR=#DD0000]"ok" [/COLOR][COLOR=#007700]){[/COLOR][COLOR=#FF8000]//chua dang nhap         [/COLOR][COLOR=#007700]echo [/COLOR][COLOR=#DD0000]'<script language="JavaScript" type="text/javascript">             document.location="http://localhost/administrator/login.php";            </script>                '[/COLOR][COLOR=#007700];}[/COLOR][COLOR=#0000BB]?>[/COLOR][COLOR=#0000BB]<?phpob_start[/COLOR][COLOR=#007700]();[/COLOR][COLOR=#0000BB]session_start[/COLOR][COLOR=#007700]();if(!isset([/COLOR][COLOR=#0000BB]$_SESSION[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'admin'[/COLOR][COLOR=#007700]])) {     [/COLOR][COLOR=#0000BB]header[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]'location:login.php'[/COLOR][COLOR=#007700]);}[/COLOR][COLOR=#0000BB]?>[/COLOR] [COLOR=#0000BB]<?php session_start[/COLOR][COLOR=#007700]();if(isset([/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"logout"[/COLOR][COLOR=#007700]]) and [/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"logout"[/COLOR][COLOR=#007700]] ==[/COLOR][COLOR=#DD0000]"ok" [/COLOR][COLOR=#007700]){    [/COLOR][COLOR=#FF8000]//xoa session dang nhap    [/COLOR][COLOR=#0000BB]$_SESSION[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"login"[/COLOR][COLOR=#007700]] = [/COLOR][COLOR=#0000BB]NULL [/COLOR][COLOR=#007700];    unset([/COLOR][COLOR=#0000BB]$_SESSION[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"login"[/COLOR][COLOR=#007700]]);    [/COLOR][COLOR=#0000BB]$_SESSION[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"username"[/COLOR][COLOR=#007700]] = [/COLOR][COLOR=#0000BB]NULL [/COLOR][COLOR=#007700];    unset([/COLOR][COLOR=#0000BB]$_SESSION[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"username"[/COLOR][COLOR=#007700]]);    [/COLOR][COLOR=#0000BB]$_SESSION[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"iduser"[/COLOR][COLOR=#007700]] = [/COLOR][COLOR=#0000BB]NULL [/COLOR][COLOR=#007700];    unset([/COLOR][COLOR=#0000BB]$_SESSION[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"iduser"[/COLOR][COLOR=#007700]]);    [/COLOR][COLOR=#FF8000]//thoat     [/COLOR][COLOR=#007700]echo [/COLOR][COLOR=#DD0000]'<script language="JavaScript" type="text/javascript">             document.location="http://localhost/administrator/login.php";            </script>    '[/COLOR][COLOR=#007700];}[/COLOR][COLOR=#0000BB]?>[/COLOR]<link href="css/FileCss.css" rel="stylesheet" type="text/css" /><table width="100%" border="1">  <tr>    <td colspan="2" align="right"><form id="logout" name="logout" method="post" action="?">    <input name="logout" type="hidden" value="ok" />      <input type="submit" name="Submit" value="Logout" />    </form>    </td>  </tr>  <tr>    <td width="18%" valign="top"><table width="100%" border="1">      <tr>        <td align="center"><a href="?mod=user">Tai khoan </a></td>      </tr>      <tr>        <td align="center"><a href="?mod=module">Module</a></td>      </tr>      <tr>        <td align="center"><a href="?mod=assignRight">Phan Quyen </a></td>      </tr>      <tr>        <td align="center"><a href="?mod=intro">Gioi thieu </a></td>      </tr>      <tr>        <td align="center"><a href="?mod=news">Tin tuc </a></td>      </tr>      <tr>        <td align="center"><a href="?mod=product">San pham </a></td>      </tr>      <tr>        <td align="center"><a href="?mod=contact">Lien he </a></td>      </tr>    </table></td>    <td align="left" valign="top">    [COLOR=#0000BB]<?php     $module [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#DD0000]""[/COLOR][COLOR=#007700];    if(isset([/COLOR][COLOR=#0000BB]$_GET[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"mod"[/COLOR][COLOR=#007700]])) [/COLOR][COLOR=#0000BB]$module [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]$_GET[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"mod"[/COLOR][COLOR=#007700]];    switch([/COLOR][COLOR=#0000BB]$module[/COLOR][COLOR=#007700])    {        case [/COLOR][COLOR=#DD0000]"assignRight"[/COLOR][COLOR=#007700]:              include([/COLOR][COLOR=#DD0000]'module/assignRight/index.php'[/COLOR][COLOR=#007700]);              break;            case [/COLOR][COLOR=#DD0000]"module"[/COLOR][COLOR=#007700]:              include([/COLOR][COLOR=#DD0000]'module/Right/index.php'[/COLOR][COLOR=#007700]);              break;                      case [/COLOR][COLOR=#DD0000]"user"[/COLOR][COLOR=#007700]:              include([/COLOR][COLOR=#DD0000]'module/User/index.php'[/COLOR][COLOR=#007700]);              break;    case [/COLOR][COLOR=#DD0000]"product"[/COLOR][COLOR=#007700]:              include([/COLOR][COLOR=#DD0000]'module/Product/index.php'[/COLOR][COLOR=#007700]);              break;    case [/COLOR][COLOR=#DD0000]"contact"[/COLOR][COLOR=#007700]:              include([/COLOR][COLOR=#DD0000]'module/Contact/index.php'[/COLOR][COLOR=#007700]);              break;    case [/COLOR][COLOR=#DD0000]"intro"[/COLOR][COLOR=#007700]:              include([/COLOR][COLOR=#DD0000]'module/Introduce/index.php'[/COLOR][COLOR=#007700]);              break;      case [/COLOR][COLOR=#DD0000]"news"[/COLOR][COLOR=#007700]:              include([/COLOR][COLOR=#DD0000]'module/News/index.php'[/COLOR][COLOR=#007700]);              break;      default :                }        [/COLOR][COLOR=#0000BB]?>[/COLOR]    </td>  </tr>  <tr>    <td colspan="2"> </td>  </tr></table>

```

đây là file index



```

[COLOR=#000000][/COLOR][COLOR=#007700]<?[/COLOR][COLOR=#0000BB]php $db_selected [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]mysql_select_db[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]'inet'[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$link[/COLOR][COLOR=#007700]);if (![/COLOR][COLOR=#0000BB]$db_selected[/COLOR][COLOR=#007700]) {    die ([/COLOR][COLOR=#DD0000]'Can\'t use inet : ' [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000BB]mysql_error[/COLOR][COLOR=#007700]());}[/COLOR][COLOR=#0000BB]?>[/COLOR][COLOR=#0000BB]<?php $username [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"username"[/COLOR][COLOR=#007700]];[/COLOR][COLOR=#0000BB]$password [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"password"[/COLOR][COLOR=#007700]];[/COLOR][COLOR=#0000BB]$sql[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]"SELECT * FROM tblUser WHERE UCASE(username) = '"[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]strtoupper[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$username[/COLOR][COLOR=#007700]).[/COLOR][COLOR=#DD0000]"' AND pass = '"[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]$password[/COLOR][COLOR=#007700].[/COLOR][COLOR=#DD0000]"'"[/COLOR][COLOR=#007700];[/COLOR][COLOR=#0000BB]$result [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]mysql_query[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$sql[/COLOR][COLOR=#007700]);[/COLOR][COLOR=#0000BB]$rowid [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#DD0000]""[/COLOR][COLOR=#007700];while([/COLOR][COLOR=#0000BB]$row [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]mysql_fetch_array[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$result[/COLOR][COLOR=#007700]))  {   [/COLOR][COLOR=#0000BB]$rowid [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]$row[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000BB]0[/COLOR][COLOR=#007700]] ;  }     [/COLOR][COLOR=#FF8000]//kiem tra co user day khong    [/COLOR][COLOR=#007700]if([/COLOR][COLOR=#0000BB]$rowid [/COLOR][COLOR=#007700]<> [/COLOR][COLOR=#DD0000]""[/COLOR][COLOR=#007700])     {         [/COLOR][COLOR=#0000BB]$_SESSION[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"login"[/COLOR][COLOR=#007700]] = [/COLOR][COLOR=#DD0000]"ok"[/COLOR][COLOR=#007700];         [/COLOR][COLOR=#0000BB]$_SESSION[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"username"[/COLOR][COLOR=#007700]] = [/COLOR][COLOR=#0000BB]strtoupper[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$username[/COLOR][COLOR=#007700]);         [/COLOR][COLOR=#0000BB]$_SESSION[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"iduser"[/COLOR][COLOR=#007700]] = [/COLOR][COLOR=#0000BB]$rowid[/COLOR][COLOR=#007700];         echo [/COLOR][COLOR=#DD0000]'<script language="JavaScript" type="text/javascript">             document.location="http://localhost/administrator/";            </script>                '[/COLOR][COLOR=#007700];    }    else    {            echo [/COLOR][COLOR=#DD0000]"Nhap sai tai khoan "[/COLOR][COLOR=#007700];    }      }[/COLOR][COLOR=#0000BB]?>[/COLOR]<center> DANG NHAP    <form id="form1" name="form1" method="post" action="login.php">   <input name="login" type="hidden" value="ok" />   <table width="60%" border="1">  <tr>    <td width="20%" align="center">Username</td>    <td width="80%"><input name="username" type="text" id="username" value="" /></td>  </tr>  <tr>    <td align="center">Password</td>    <td><input name="password" type="password" id="password" value="" /></td>  </tr>  <tr>    <td> </td>    <td><input type="submit" name="Submit" value="Dang nhap " /></td>  </tr></table>   </form> </center>

```

[/PHP]

----------

