[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 170
  • Last Modified:

constant variables problem

in the mysql_connect.inc
 
define('ADMIN_NAME','admin');
and many more...

in the footer.inc i have this

?php if($_POST['username'] == $_POST[ADMIN_NAME]){
 echo '<a href="admin/administrator.php">administrator</a>';
} else {echo "<a href=\"./index.php\">Home</a>"; } ?>

if the username is equal to ADMIN_NAME constant which is 'admin'
the link that will be displayed will be ADMINISTRATOR
if the username is not 'admin'
the link that will be displayed will be HOME

but there's one problem. if i used that $_POST[ADMIN_NAME] the link will be ADMINISTRATOR
even if the username is not equal to 'admin'
please help!!! i need it badly!
0
crazy_beautiful
Asked:
crazy_beautiful
  • 3
1 Solution
 
stefanaichholzerCommented:
I would suggest somethig like this, better and more secure:

The include file, which should be required once:

<?php
 session_start();
 $_SESSION[data][adminName] = "Administrator";
?>

The other files:

<?php
 if($_POST['username'] == $_SESSION[data][adminName])
  {
   echo '<a href="admin/administrator.php">administrator</a>';
  }
 else
  {
   echo "<a href=\"./index.php\">Home</a>";
  }
?>

Let me know how it goes...

;)
0
 
gruntarCommented:
You must use defined constant like this;
if($_POST['username'] == ADMIN_NAME){
or
if($_POST['username'] == constant("ADMIN_NAME")){

Cheers
0
 
gruntarCommented:
Hi, stefanaichholzer didn't give him the right answer how to use constant variables... I belive I did.

Cheers
0
 
gruntarCommented:
No problem.  I wasn't paying attention to points. :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now