User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 426,659 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,549 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 871 | Replies: 22 | Solved
Reply
Join Date: Jan 2008
Posts: 70
Reputation: Vai is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 5
Vai Vai is offline Offline
Junior Poster in Training

Little code confusion

  #1  
May 15th, 2008
After logging in, main.php is loaded and instead of displaying the correct included page, it displays Main Page.

So what is wrong w/ my code?

Thanks in advance for any and all help...

this is placed inside the "main.php"

<?php 
    require('core/db.php');
    require('core/check.php');
?>
  
This is placed inside the check.php

<?php
    if (level == "1")  { include('page_1.php'); } 
     else 
    if (level == "2") { include('page_2.php'); }
     else 
    if (level == "3") { include('page_3.php'); }
?>   
Inside the pages I have 
<?php 
   echo "Page_Name";
?>

AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: Little code confusion

  #2  
May 15th, 2008
<?php
if (level == "1") { include('page_1.php'); }
else
if (level == "2") { include('page_2.php'); }
else
if (level == "3") { include('page_3.php'); }
?>
Shouldn't level be $level ?
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Jan 2008
Posts: 70
Reputation: Vai is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 5
Vai Vai is offline Offline
Junior Poster in Training

Re: Little code confusion

  #3  
May 15th, 2008
Originally Posted by nav33n View Post
Shouldn't level be $level ?

nav33n,
Yea, I changed level to $level, but it still didn't change anything. I am unsure what else needs to be changed as far as the login form is concerned.

Here is the code for everything I have:
Log In form:

<?php
  session_start();
  if(isset($_GET['reg'])) 
   {
    $reg=$_GET['reg'];
  }
   else
    {
     $reg="";
    }
   if($reg==1) 
    {
     $msg1="<font color=\"#FF0000\"><b>Your details have been added, 
            please login</b></font>"; }    
     elseif($reg==2) {
      $msg1="<font color=\"#FF0000\"><b>You have been successfully logged out.</b></font>";
}

     if(isset($_POST['submit'])) {
      if( empty($_POST['username']) && (empty($_POST['password']))) {
       header( "Location:core/Messages.php?msg=1" ); 
      exit();
}

//transfer to shorter var

$n=$_POST['username'];
$p=$_POST['password'];

//connect to db
  require_once('core/db.php');
   $query="select username, password from admin where username='$n' and password='$p' ";
   $result=mysql_query($query);
	
   $num=mysql_num_rows($result);
    if($num>0 ){
   
//put in session vars
   $_SESSION['status'] = 'logged';
   $_SESSION['username'] = $n;

//goto next page
   header("location:main.php");
    exit;
     } else {
      $_SESSION['status'] = 'not logged';

   header( "Location:core/Messages.php?msg=2" ); 
    exit();
    }
  }
?>
<!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=iso-8859-1" />
<title>Title goes here</title>
</head>

<body>
<form action='index.php' method='post' class="login_form">
<table border="0"cellpadding="2" cellspacing="2" >
<tr> 
 <td>Username:</td>
 <td><input name="username" type="text" id="username" size="30"></td>
</tr>
<tr> 
 <td>Password:</td>
 <td><input name="password" type="password" id="password" size="30" class="password"></td>
</tr>
<tr>
 <td colspan="2" align=center><input type='submit' name='submit' value='login'></td>
</tr>
</table>
</form>
</body>
</html>
___________________________________________________________________________________________
secure.php

<?php
  session_start();
  if (empty($_SESSION['username'])) 
   { header("location:../index.php");
     exit; 
  }
 ?>
___________________________________________________________________________________________
check.php

<?php
  if ($level == "1") { include('page_1.php'); } 
   else 
  if ($level == "2") { include('page_2.php'); }
  else 
  if ($level == "3") { include('page_3.php'); }
?>


Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: Little code confusion

  #4  
May 15th, 2008
Okay.. Where are you setting a value to $level ?
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Jan 2008
Posts: 70
Reputation: Vai is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 5
Vai Vai is offline Offline
Junior Poster in Training

Re: Little code confusion

  #5  
May 15th, 2008
Originally Posted by nav33n View Post
Okay.. Where are you setting a value to $level ?

I just realized I wasn't.
So I added
$_SESSION["level"] = 1; 
$_SESSION["level"] = 2; 
$_SESSION["level"] = 3; 
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: Little code confusion

  #6  
May 15th, 2008
Also, in check.php, don't forget to assign $_SESSION['level'] value to $level.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Jan 2008
Posts: 70
Reputation: Vai is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 5
Vai Vai is offline Offline
Junior Poster in Training

Re: Little code confusion

  #7  
May 15th, 2008
Now it works, it just displays page_1.php for all users logging in.
$_SESSION["level"] = 1; 
$_SESSION["level"] = 2;
$_SESSION["level"] = 3;


check.php source:

<?php
  if ($level = "1") { 
   include('page_1.php');  } 
   else 
  if ($level = "2") { include('page_2.php'); }

   else 
  if ($level = "3") { include('page_3.php'); }
?> 
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: Little code confusion

  #8  
May 15th, 2008
Its $level == "1" and so on.. And why not use just if conditions ? ie.,
  1. $level = $_SESSION['level'];
  2. if ($level == "1") {
  3. include "page_1.php";
  4. }
  5. if($level == "2") {
  6. include "Page_2.php";
  7. }
  8. //and so on..
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Jan 2008
Posts: 70
Reputation: Vai is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 5
Vai Vai is offline Offline
Junior Poster in Training

Re: Little code confusion

  #9  
May 17th, 2008
Nav33n,
I have tried to the code in every which way possible. Nothing I do works correctly.
All I get is page_1.php to load no matter what.

Here is the code that I have now...

index.php
  1. $level = $_SESSION['level'];
  2. $_SESSION["level"] = 1;
  3. $_SESSION["level"] = 2;
  4. $_SESSION["level"] = 3;

check.php
  1. <?php
  2. $level = $_SESSION['level'];
  3. if ($level == "1") { include "page_1.php"; }
  4. else
  5. if ($level == "2") { include "page_2.php"; }
  6. else
  7. if ($level == "3") { include "page_3.php"; }
  8. ?>
This displays nothing.
When I change it to:
  1. <?php
  2. if ($level = "1") { include "page_1.php"; }
  3. else
  4. if ($level = "2") { include "page_2.php"; }
  5. else
  6. if ($level = "3") { include "page_3.php"; }
  7. ?>
This will display page_1 no matter what the level is...
Please excuse my ignorance. Thanks for any and all help.
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: Little code confusion

  #10  
May 18th, 2008
$level = 1 isn't correct. Since you are comparing the value of $level, you need to use comparison operator. http://nl.php.net/operators.comparison
Secondly, where are you assigning the value to $_SESSION['level'] ? I think the value is being overwritten or something. Btw, there is no session_start() in check.php. When you assign the value to the session variable, check whats in it. In check.php, check print out the session variable value and cross check !
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 1:45 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC