•
•
•
•
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
![]() |
•
•
Join Date: Jan 2008
Posts: 70
Reputation:
Rep Power: 1
Solved Threads: 5
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...
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";
?>
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
•
•
•
•
<?php
if (level == "1") { include('page_1.php'); }
else
if (level == "2") { include('page_2.php'); }
else
if (level == "3") { include('page_3.php'); }
?>
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*
*PM asking for help will be ignored*
•
•
Join Date: Jan 2008
Posts: 70
Reputation:
Rep Power: 1
Solved Threads: 5
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'); }
?>
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
•
•
Join Date: Jan 2008
Posts: 70
Reputation:
Rep Power: 1
Solved Threads: 5
I just realized I wasn't.
So I added
$_SESSION["level"] = 1; $_SESSION["level"] = 2; $_SESSION["level"] = 3;
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
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*
*PM asking for help will be ignored*
•
•
Join Date: Jan 2008
Posts: 70
Reputation:
Rep Power: 1
Solved Threads: 5
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'); }
?> •
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
Its $level == "1" and so on.. And why not use just if conditions ? ie.,
php Syntax (Toggle Plain Text)
$level = $_SESSION['level']; if ($level == "1") { include "page_1.php"; } if($level == "2") { include "Page_2.php"; } //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*
*PM asking for help will be ignored*
•
•
Join Date: Jan 2008
Posts: 70
Reputation:
Rep Power: 1
Solved Threads: 5
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
check.php
This displays nothing.
When I change it to:
This will display page_1 no matter what the level is...
Please excuse my ignorance. Thanks for any and all help.
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
php Syntax (Toggle Plain Text)
$level = $_SESSION['level']; $_SESSION["level"] = 1; $_SESSION["level"] = 2; $_SESSION["level"] = 3;
check.php
php Syntax (Toggle Plain Text)
<?php $level = $_SESSION['level']; if ($level == "1") { include "page_1.php"; } else if ($level == "2") { include "page_2.php"; } else if ($level == "3") { include "page_3.php"; } ?>
When I change it to:
php Syntax (Toggle Plain Text)
<?php if ($level = "1") { include "page_1.php"; } else if ($level = "2") { include "page_2.php"; } else if ($level = "3") { include "page_3.php"; } ?>
Please excuse my ignorance. Thanks for any and all help.
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
$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 !
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*
*PM asking for help will be ignored*
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
access activation api blogger blogging blogs code code injection combo dani daniweb data debugging development dreamweaver dropdownlist epilepsy gdata google gpl griefers hackers html innovation javascript key linux microsoft module net news openbsd product programming reuse rss serial source tags vista web wysiwyg xml
- Code Confusion (C#)
- Php code confusion. Not sure how to describe (PHP)
- Confusion in string handling? (C)
- String Object Immutable Confusion (Java)
- A little help please? thanks. (C++)
- Pointer Confusion (C++)
Other Threads in the PHP Forum
- Previous Thread: php search form with paged results proplem
- Next Thread: help with menu selection based from other menu showing "selected" entry from db



Linear Mode