2014-03-13 1 views
0

을 만들려고 노력 해요 :내가 포럼을 만들기 위해 PHP를 사용하고이 내 "config.php를"파일 사용자 그룹

<?php 
/****************************************************** 
------------------Required Configuration--------------- 
Please edit the following variables so the forum can 
work correctly. 
******************************************************/ 

//We log to the DataBase 
mysql_connect('', '', ''); 
mysql_select_db(''); 

//Username of the Administrators 
$admin='Hexagon'; 
$mod='test1'; 

/****************************************************** 
-----------------Optional Configuration---------------- 
******************************************************/ 

//Forum Home Page 
$url_home = 'index.php'; 

//Design Name 
$design = 'default'; 


/****************************************************** 
----------------------Initialization------------------- 
******************************************************/ 
include('init.php'); 
    ?> 

이 내 "delete_topic.php"파일입니다

<?php 
//This page let delete a topic 
include('config.php'); 
if(isset($_GET['id'])) 
{ 
    $id = intval($_GET['id']); 
if(isset($_SESSION['username'])) 
{ 
    $dn1 = mysql_fetch_array(mysql_query('select count(t.id) as nb1, t.title, t.parent, c.name from topics as t, categories as c where t.id="'.$id.'" and t.id2=1 and c.id=t.parent group by t.id')); 
if($dn1['nb1']>0) 
{ 
if($_SESSION['username']==$admin) 
if($_SESSION['username']==$mod) 
{ 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
     <link href="<?php echo $design; ?>/style.css" rel="stylesheet" title="Style" /> 
     <title>Delete a topic - <?php echo htmlentities($dn1['title'], ENT_QUOTES, 'UTF-8'); ?> - <?php echo htmlentities($dn1['name'], ENT_QUOTES, 'UTF-8'); ?> - Forum</title> 
    </head> 
    <body> 
     <div class="header"> 
      <a href="<?php echo $url_home; ?>"><img src="<?php echo $design; ?>/images/logo.png" alt="Forum" /></a> 
     </div> 
     <div class="content"> 
<?php 
$nb_new_pm = mysql_fetch_array(mysql_query('select count(*) as nb_new_pm from pm where ((user1="'.$_SESSION['userid'].'" and user1read="no") or (user2="'.$_SESSION['userid'].'" and user2read="no")) and id2="1"')); 
$nb_new_pm = $nb_new_pm['nb_new_pm']; 
?> 
<div class="box"> 
    <div class="box_left"> 
     <a href="<?php echo $url_home; ?>">Forum Index</a> &gt; <a href="list_topics.php?parent=<?php echo $dn1['parent']; ?>"><?php echo htmlentities($dn1['name'], ENT_QUOTES, 'UTF-8'); ?></a> &gt; <a href="read_topic.php?id=<?php echo $id; ?>"><?php echo htmlentities($dn1['title'], ENT_QUOTES, 'UTF-8'); ?></a> &gt; Delete the topic 
    </div> 
    <div class="box_right"> 
     <a href="list_pm.php">Your messages(<?php echo $nb_new_pm; ?>)</a> - <a href="profile.php?id=<?php echo $_SESSION['userid']; ?>"><?php echo htmlentities($_SESSION['username'], ENT_QUOTES, 'UTF-8'); ?></a> (<a href="login.php">Logout</a>) 
    </div> 
    <div class="clean"></div> 
</div> 
<?php 
if(isset($_POST['confirm'])) 
{ 
    if(mysql_query('delete from topics where id="'.$id.'"')) 
    { 
    ?> 
    <div class="message">The topic have successfully been deleted.<br /> 
    <a href="list_topics.php?parent=<?php echo $dn1['parent']; ?>">Go to "<?php echo htmlentities($dn1['name'], ENT_QUOTES, 'UTF-8'); ?>"</a></div> 
    <?php 
    } 
    else 
    { 
     echo 'An error occured while deleting the topic.'; 
    } 
} 
else 
{ 
?> 
<form action="delete_topic.php?id=<?php echo $id; ?>" method="post"> 
    Are you sure you want to delete this topic? 
    <input type="hidden" name="confirm" value="true" /> 
    <input type="submit" value="Yes" /> <input type="button" value="No" onclick="javascript:history.go(-1);" /> 
</form> 
<?php 
} 
?> 
     </div> 
     <div class="foot"><a href="http://www.webestools.com/scripts_tutorials-code-source-26-simple-php-forum-script-php-forum-easy-simple-script-code-download-free-php-forum-mysql.html">Simple PHP Forum Script</a> - <a href="http://www.webestools.com/">Webestools</a></div> 
    </body> 
</html> 
<?php 
} 
else 
{ 
    echo '<h2>You don\'t have the right to delete this topic.</h2>'; 
} 
} 
else 
{ 
    echo '<h2>The topic you want to delete doesn\'t exist.</h2>'; 
} 
} 
else 
{ 
    echo '<h2>You must be logged as an administrator to access this page: <a href="login.php">Login</a> - <a href="signup.php">Sign Up</a></h2>'; 
} 
} 
else 
{ 
    echo '<h2>The ID of the topic you want to delete is not defined.</h2>'; 
} 

?> 

아직 어떤 이유로 $ mod 그룹의 사용자는 주제를 삭제할 수 없습니다. 주제를 삭제하고 게시물을 편집 할 수 있도록 운영자가 필요하기 때문에 잠시 나를 괴롭 히고 있지만 주제를 삭제할 수도 없습니다. 어떤 제안? 이것은 내가 작업하고있는 정말 큰 프로젝트이며, mods와 admins가 서로 다를 수 있다는 점이 중요합니다. 조건은 $ 관리자가 충족되지 않으면

if($_SESSION['username']==$admin) 
if($_SESSION['username']==$mod) 
{ 

, 당신은 자신을 발견하고 무엇이 일어나고있는 것은 ..

+0

을 다음과 같이 해당 세션에 대해 확인하실 수 있습니다보다
. 사실, 당신도 아마 자신을 도울 것입니다. – Tristan

답변

0

귀하의 문제가 여기에있다 [BTW, 데이터베이스 정보는 MY config.php 파일에 작성됩니다] 삭제 허용 블록에서 ... 난 당신이 MySQL을가되지 않습니다으로이 대신

if($_SESSION['username']==$mod || $_SESSION['username']==$admin) 
{ 

는 또한 mysqli를 사용하여 시작하십시오 할 수 있습니다 생각합니다.

+0

슬프게도 작동하지 않았습니다. –

+0

당신은 seesion을 시작했고 $ _SESSION 변수에 기대 한 바가 있는지 확인했습니다. – Bryan

+0

및 무엇이 작동하지 않는다는 것을 의미합니까? 양식을 보거나 메시지가 무엇입니까? – Bryan

1

이 문제를 밖으로 정렬하는 좋은 방법은, 사용자 (또는 회원) 테이블에서 필드를 만들고 1로
관리자 설정이 필드 "user_levels"를 호출하는 것입니다
중재자 2,
다른 회원 등 3 또는 공란 또는 0 (원하는대로). 당신이 제대로 PHP 코드를 포맷은 쉽게 사람들이 당신을 도와 할 수 있도록 할 경우 세션 $_SESSION['user_levels']를 설정하고 항상

if ($_SESSION['user_levels']==1 || $_SESSION['user_levels']==2) 
{ 
    // Grant him permission to delete the record 
} 
else 
{ 
    // tell him that he is not authorize to delete it 
} 
+0

OK ... 이걸 시도해 볼게. 감사합니다 –

+0

@ user3394931 당신이 내 대답을 좋아한다면, 대답의 왼쪽에있는 눈금을 클릭하여 대답을 수락하십시오. 감사합니다. – Bangash

관련 문제