943,640 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1167
  • PHP RSS
Mar 20th, 2008
0

Please Help ... $rank_check = 5; ???Using IF statement to allow multiple rank access

Expand Post »
Hello everyone,

I really really need some help with this as Ive been trying to sort since December and cannot seem to get past it. I only know very basic PHP and still currently learning.

Basically I have a website with multiple pages and a membership system which has a ranking system for my members. The access to a page is set by the $rank_check = 5; statement which allows access to that particular rank and above. If I use the $rank_check == 5; then this will make access to that page ONLY for that rank which is great.

However, I currently have ranks between 1-99 and really need to be able to set the page access to allow which ever ranks I state otherwise admin could be accessed by unauthorised members.

So for example, if I want page 1 to have access to every rank above 5 then I can set it as: $rank_check = 5;

If I want page 2 to have access to ONLY rank 67 then I can use the $rank_check == 67; which is fine.

However, how do I set it so that I can set page 3 to allow access to for multiple ranks .... example ... ranks 5, 7, 48,67 and 99????

I have tried using the If statements. Also tried using the && statements along with the $rank_check == 5; but it didnt work. :O(

PLEASE PLEASE PLEASE help me and I will be eternally grateful. lol

Here is the actual document code:

PHP Syntax (Toggle Plain Text)
  1.  
  2.  
  3. <?php
  4.  
  5. /*
  6.  
  7. Admin Main (admin.php)
  8.  
  9. */
  10.  
  11. $page_title = "Admin - Founder Highly Restricted";
  12.  
  13. $rank_check = 5;
  14.  
  15. include "../header.inc.php";
  16.  
  17.  
  18.  
  19. print "$openHTML";
  20.  
  21. ECHO <<<END
  22. PAGE CONTENT HERE
  23. END;
  24.  
  25.  
  26.  
  27. print "$closeHTML";
  28.  
  29. ?>

Here are some attempts at what I have tried using so far:

PHP Syntax (Toggle Plain Text)
  1.  
  2. if($rank_check == 6 || $rank_check == 7 || $rank_check == 8){ include "../header.inc.php";
  3.  
  4. $page_title = "admin_access6.php";
  5. $rank_check == 6 || $rank_check == 7 || $rank_check == 8;
  6.  
  7. if($rank_check == "6" || $rank_check == "7" || $rank_check == "8"){ $let_them_pass = true;}
  8.  
  9. if($set_rank == 6 || $set_rank == 7 || $set_rank == 8){ $let_them_pass = true;}
  10.  
  11. <?php $page_title = "admin_access6.php";if($rank_check != 6 && $rank_check != 7 && $rank_check != 8){ exit;}include "../header.inc.php"; print "$openHTML"; $credit = $getGame[credit] / 100; ECHO <<<END

None of these seemed to work.

Hope someone can help me as this is a really big and urgent job I need on my website.

Thanks you so much

Justin :o)
Reputation Points: 10
Solved Threads: 2
Junior Poster
justted is offline Offline
140 posts
since Dec 2007
Mar 21st, 2008
1

Re: Please Help ... $rank_check = 5; ???Using IF statement to allow multiple rank ac

Try this (assuming that $set_rank is the user's rank):

PHP Syntax (Toggle Plain Text)
  1. $rank_check = 5; // the page rank
  2. $let_them_pass = false;
  3. if($set_rank > $rank_check) {
  4. $let_them_pass = true;
  5. }
  6.  
  7. if($let_them_pass == true) {
  8. // do stuff
  9. }

You only need check against $let_them_pass being either true or false.



Matti Ressler
Suomedia
Last edited by Suomedia; Mar 21st, 2008 at 1:07 am.
Reputation Points: 15
Solved Threads: 19
Junior Poster
Suomedia is offline Offline
154 posts
since Mar 2008
Mar 21st, 2008
0

Re: Please Help ... $rank_check = 5; ???Using IF statement to allow multiple rank access

Hiya,

Thanks so much for the reply. So how exactly would I add this to my page. And from what I can see it will only allow the rank of 5 to access it??

Sorry I cant seem to get my head round it.

Justin
Reputation Points: 10
Solved Threads: 2
Junior Poster
justted is offline Offline
140 posts
since Dec 2007
Mar 21st, 2008
0

Re: Please Help ... $rank_check = 5; ???Using IF statement to allow multiple rank ac

I am assuming that $set_rank contains the access level of your user, while $page_rank is the access level for the page. To give access to a $set_rank of 5 or above use:

PHP Syntax (Toggle Plain Text)
  1. if($set_rank >= $rank_check) {
  2. $let_them_pass = true;
  3. }

What you posted is rather confusing, so I am just doing it my way.

Matti Ressler
Suomedia
Last edited by Suomedia; Mar 21st, 2008 at 1:29 am.
Reputation Points: 15
Solved Threads: 19
Junior Poster
Suomedia is offline Offline
154 posts
since Mar 2008
Mar 21st, 2008
0

Re: Please Help ... $rank_check = 5; ???Using IF statement to allow multiple rank access

Ah I can already give access to rank 5 and above, and I know how to give access to ONLY rank 5....

What I want to be able to do is alloacte exactly which ranks has access to a page. Like for example... rank 5, 10, 13 and 48 can access a page.

The $set_rank contains the rank list which is correct.

:o/ Does that make sense to you now?

Thanks so much
Reputation Points: 10
Solved Threads: 2
Junior Poster
justted is offline Offline
140 posts
since Dec 2007
Mar 21st, 2008
0

Re: Please Help ... $rank_check = 5; ???Using IF statement to allow multiple rank ac

Ok... now you have explained better. Try this:


PHP Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. /*
  4.  
  5. Admin Main (admin.php)
  6.  
  7. */
  8.  
  9. $rank_check = array(5, 10, 13, 28); // ranks allowed to access this page
  10.  
  11. $let_them_pass = false;
  12. if(in_array($set_rank,$rank_check)) { // $set_rank is the user's access level
  13. $let_them_pass = true;
  14. }
  15.  
  16. if($let_them_pass == false) {
  17. header("location:http://www.url.com/other_page.php"); // access denied, redirect user to another page.
  18. }
  19.  
  20. $page_title = "Admin - Founder Highly Restricted";
  21.  
  22. include "../header.inc.php";
  23.  
  24. print "$openHTML";
  25.  
  26. ECHO <<<END
  27. PAGE CONTENT HERE
  28. END;
  29.  
  30. print "$closeHTML";
  31.  
  32. ?>


Matti Ressler
Suomedia
Reputation Points: 15
Solved Threads: 19
Junior Poster
Suomedia is offline Offline
154 posts
since Mar 2008
Mar 21st, 2008
0

Re: Please Help ... $rank_check = 5; ???Using IF statement to allow multiple rank access

Heya,

Thanks for your help. Thats didnt work and actually just logged me out to the log in page saying I do not have access each time regardless of the ranks I used.

Im trying to work out how it all links together and have this page which is the admin_set_status.php page

PHP Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. /*
  4. Process Set Status (admin_status.pro.php)
  5. */
  6.  
  7. $rank_check == 99;
  8. include "../global.inc.php";
  9.  
  10. $set_username = strtolower(ereg_replace(" ", "", $set_username));
  11.  
  12. mysql_query("UPDATE members2 SET rank=$set_rank WHERE username = '$set_username' AND game = '$game'");
  13. $findUser = fetch("SELECT id FROM members2 WHERE username = '$set_username' AND game = '$game'");
  14.  
  15. if ($set_rank == 0)
  16. {
  17. mysql_query("DELETE FROM forum_replies2 WHERE author = '$findUser[id]' AND game = '$game'");
  18. mysql_query("DELETE FROM forum_subjects2 WHERE author = '$findUser[id]' AND game = '$game'");
  19. }
  20.  
  21. $rank = array("Suspended", "Mute", "Under 13", "Member", "City Guides", "News Reporter", "Member Support Officer", "Senior City Guide", "Committee Manager", "Mayors Secretary", "Police Cadets", "Job Centre Manager", "Lottery Manager", "Media Manager", "Games Centre Manager", "Community Engineer", "Police Seargeant", "Police Inspector", "Police Chief Inspector", "Police Superintendent", "Police Chief Superintendent", "Deputy Chief of Police", "Chief of Police", "Deputy Mayor", "Mayor", "Chief Engineer", "CPW Founder");
  22.  
  23. record("Changed Status", "$username changed $set_username's status to $rank[$set_rank]", $timestamp, $game, $userid);
  24.  
  25. header("Location: admin_set_status.php?game=$game&error=You+have+changed+their+rank+successfully.");
  26.  
  27. ?>

Im not sure if its the $set_rank thats causing the problem.

:>s


Thanks so much

Justin
Reputation Points: 10
Solved Threads: 2
Junior Poster
justted is offline Offline
140 posts
since Dec 2007
Mar 21st, 2008
0

Re: Please Help ... $rank_check = 5; ???Using IF statement to allow multiple rank ac

I don't see or know where you are setting the value for $set_rank. The code I posted works just fine if $set_rank is properly set as the user's access level.

You can check this with:

PHP Syntax (Toggle Plain Text)
  1. echo $set_rank; die();

You really need to clean up your code properly, eg. your queries should be written like this:

PHP Syntax (Toggle Plain Text)
  1. mysql_query("UPDATE members2 SET rank ='" . $set_rank . "' WHERE username = '" . $set_username . "' AND game = '" . $game . "'");



Matti Ressler
Suomedia
Reputation Points: 15
Solved Threads: 19
Junior Poster
Suomedia is offline Offline
154 posts
since Mar 2008
Mar 21st, 2008
0

Re: Please Help ... $rank_check = 5; ???Using IF statement to allow multiple rank access

Hello again,

Im going to try and work through what you have just written. thanks.

Would this be the place?

PHP Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. ob_start();
  4. include "globals.inc.php";
  5.  
  6. $con=mysql_connect($db_server,$db_username,$db_password);
  7. //connection string
  8.  
  9. mysql_select_db($db_name,$con);
  10. //select db
  11.  
  12. include "func.lib.php";
  13.  
  14. srand((double)microtime()*1000000);
  15.  
  16. $getGame = fetch("SELECT * FROM game_tables WHERE id = '$game'");
  17. $game = $getGame[id];
  18. $gameName = "$getGame[game_name]</a>";
  19.  
  20. if ($getGame[use_logo] == "1")
  21. {
  22. $gameName = "<img src=$base_url/images/user_images/opg_$game/logo.gif></a>";
  23. }
  24. $gameName2 = "$getGame[game_name]";
  25. $pointVar = "$getGame[point_var]";
  26. $pointsVar = "$getGame[point_var]";
  27.  
  28. if (!$pointVar) { $pointVar = "$defaultPointsVariable"; }
  29.  
  30. $userCookie = "username_$game";
  31. $passCookie = "password_$game";
  32.  
  33. $getInfo = fetch("SELECT * FROM members2 WHERE username = '$HTTP_COOKIE_VARS[$userCookie]' AND password = '$HTTP_COOKIE_VARS[$passCookie]' AND game = '$game'");
  34. //echo "SELECT * FROM members2 WHERE username = '$HTTP_COOKIE_VARS[$userCookie]' AND password = '$HTTP_COOKIE_VARS[$passCookie]' AND game = '$game'";
  35. $getInfo2 = fetch("SELECT * FROM members_profiles2 WHERE username = '$getInfo[username]' AND game = '$game'");
  36. //echo "SELECT * FROM members_profiles2 WHERE username = '$getInfo[username]' AND game = '$game'";
  37. $username = $getInfo[username];
  38. $display_name = $getInfo[display_name];
  39. $userid = $getInfo[id];
  40. $points = $getInfo[points];
  41. $rank = $getInfo[rank];
  42. $hungerLevel = $getInfo[hunger_level];
  43. //print_r($getInfo);
  44.  
  45. if (!$username)
  46. {
  47. $username = "<i>Not logged in.</i>";
  48. }
  49.  
  50. else
  51. {
  52. $sql_name="usrname";
  53. $membername=$username;
  54. $u=$HTTP_COOKIE_VARS[$passCookie];
  55. $_email= $getInfo2[email];
  56. $memberid= $getInfo[id];
  57. $tmp=mysql_query("SELECT * FROM pro_membersu_privchatf WHERE usrname = '$membername' LIMIT 1");
  58. while($e=mysql_fetch_array($tmp))
  59. {
  60. $_id = ($e['id']);
  61. }
  62. // if password exists, get users email (default table)
  63. $sql="SELECT * FROM pro_membersu_privchatf WHERE ".$sql_name."='$membername' LIMIT 1";
  64. $tmp=mysql_query($sql) or die(mysql_error().$sql);;
  65. while($log_in=mysql_fetch_array($tmp))
  66. {
  67. $_email = ($log_in[$sql_email]);
  68. }
  69.  
  70. if ($_id == '')
  71. {
  72. // if first visit, add member to MEMBERS table
  73. $sql = "INSERT INTO pro_membersu_privchatf (id,usrname, usrpassword, e_mail, age, gender, location, hobbies, aboutme, terms, date, photo)
  74. VALUES ('$memberid','$membername', '$u', '$_email', '', '', '', '', '', '', NOW(), '')";mysql_query($sql) or die(mysql_error());
  75. $tmp=mysql_query("SELECT * FROM pro_membersu_privchatd WHERE membername = '$membername' order by id DESC LIMIT 1");
  76. while($e=mysql_fetch_array($tmp))
  77. {
  78. $_name = ($e['id']);
  79. }
  80.  
  81. if ($_name == '')
  82. {
  83. // if first visit, add member to ONLINE table
  84. $system_c = date("U");
  85. $sql = "INSERT INTO pro_membersu_privchatd (memberid, membername, status, ontime, active)
  86. VALUES ('$memberid', '$membername', 'Online', '$today', '$system_c')";mysql_query($sql) or die(mysql_error());
  87. }
  88. }
  89.  
  90.  
  91. }
  92. if (!$display_name) { $display_name = "<i>Not logged in.</i>"; }
  93. if (!$points) { $points = "0"; }
  94.  
  95. if ($getInfo[hunger_level] > 10) { mysql_query("UPDATE members SET hunger_level = 10 WHERE id = '$userid' AND game = '$game'"); $hungerLevel = 10;}
  96.  
  97. if ($getInfo[hunger_level] < 0) { mysql_query("UPDATE members SET hunger_level = 0 WHERE id = '$userid' AND game = '$game'"); $hungerLevel = 0; }
  98.  
  99. $hungerLevel = $hungerArray[$hungerLevel];
  100.  
  101. if (!$rank_check) { $rank_check = 0; }
  102. if (!$rank) { $rank = 0; }
  103. if ($rank < $rank_check)
  104. {
  105. //exit;
  106. die(header(error("$base_url/login.php?game=$game","$noAccessError")));
  107. }
  108.  
  109. #############
  110. ######## Hits
  111. mysql_query("UPDATE hits SET hits = hits + 1");
  112.  
  113. mysql_query("UPDATE game_tables SET hits=$getGame[hits]+1 WHERE id = '$game'");
  114.  
  115. $current_date = "$getGame[the_current_date]";
  116. $zeroHits = "0";
  117. if ($datestamp != "$current_date")
  118. {
  119. mysql_query("UPDATE game_tables SET daily_page_views=0 WHERE the_current_date != '$datestamp'") or die ("Database error: ".mysql_error());
  120. mysql_query("UPDATE game_tables SET the_current_date = '$datestamp' WHERE the_current_date != '$datestamp'") or die ("Database error: ".mysql_error());
  121. $getGame[daily_page_views] = 0;
  122. }
  123.  
  124. mysql_query("UPDATE game_tables SET daily_page_views = daily_page_views + 1 WHERE id = '$game'");
  125.  
  126. #############
  127.  
  128. ?>

This is the global document. For some reason I cannot get my head around the $set_rank for some reason. lol

I basically brought the script that said it would have 100% support etc but when I got it the guy never ever replied to tech problems and Ive noticed this has been common with other people.

So I have basically had to learn as much PHP/MySql as I can and try and get it all fixed and changed myself. So far ive managed to do lots but this has been a constant problem. lol

Thanks for letting me know about the need to clean it up

Justin
Reputation Points: 10
Solved Threads: 2
Junior Poster
justted is offline Offline
140 posts
since Dec 2007
Mar 21st, 2008
0

Re: Please Help ... $rank_check = 5; ???Using IF statement to allow multiple rank ac

That does not contain $set_rank .... the only thing that I can see close to it is:

PHP Syntax (Toggle Plain Text)
  1. $rank = $getInfo[rank];

Perhaps $set_rank is set in globals.inc.php as I would expect it to be registered in the user session.


Matti Ressler
Suomedia
Reputation Points: 15
Solved Threads: 19
Junior Poster
Suomedia is offline Offline
154 posts
since Mar 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Login question php??
Next Thread in PHP Forum Timeline: online transaction system





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC