PDA

View Full Version : how to do index.php?panel=1 like this ?



GregT
November 6th, 2002, 18:11
how would i do this ? right now i have



if(!$login) {
include("templates/login.tmpl");
}
?><?
if($panel==1) {
include("templates/panel.tmpl");
}

but on the panel=1 page the login also appears. how do write this so that only the defined template display for that word ?
like

index.php?panel=1 would go to templates/panel.tmpl
but one that is not in there would goto the login page ?

Dusty
November 6th, 2002, 18:22
I'd assume panel.tmpl is only to be shown if the user is logged-in ($login is true)?


if($login){
if($panel==1){
include('templates/panel.tmpl');
}
}else{
include('templates/login.tmpl');
}

GregT
November 6th, 2002, 19:15
yes, but i havent written the login system yet ... :biggrin2: i also need to have multiple things, that again are only so be shown if the user is logged in. all the features are in file and use a template system im writting. i need to have about 5 other features using ?modulename=1 like that. how would i go about doing that ?
would it be like
?


if($login){
if($panel==1){
include('templates/panel.tmpl');
}
if($logout==1){
include('templates/logout.tmpl');
}

}else{
include('templates/login.tmpl');
}

Who?
November 6th, 2002, 20:04
if($login){
if($panel==1){
include('templates/panel.tmpl');

} else if($logout==1){
include('templates/logout.tmpl');
}

}else{
include('templates/login.tmpl');
}

GregT
November 6th, 2002, 20:59
do i just an more else if's for more functions to the file ?

biggulp
November 6th, 2002, 21:49
if (isset($login)) is recommended over if ($login)

GregT
November 6th, 2002, 21:49
here what i have now



if(!isset($_COOKIE['LoggedIn']))
{
if($panel==1){
include('$panel_tmpl');
}

else if($logout==1){
include('$logout_tmpl');
}

else if($hostingmailer==1){
include('$hostingmailer_tmpl');
}

else if($adminmailsend==1){
include('$adminmailsend_tmpl');
}

else {
include('$login_tmpl'); }

GregT
November 6th, 2002, 21:51
Originally posted by biggulp
if (isset($login)) is recommended over if ($login)

i know im using it :D

hohoho
November 7th, 2002, 09:33
if($somevar=="1")

don't forget the "

Dusty
November 7th, 2002, 13:22
if (isset($login)) is recommended over if ($login)No, that wouldn't work at all. If $login is a boolean true/false-- as it appears to be from Raz0r's use of it-- then "if($login)" is the most logical way to test if it's true. Were you to do "if(isset($login))" on a boolean it would always return true, as even if $login is false it's still set. Try it:
$login=false;
if($login){
print 'This won\\'t show as $login is false';
}
if(isset($login)){
print 'Despite $login being false, this is shown';
}If you don't like "if($login)" you could do "if($login==true)", but there's really no point to that.

You've got a problem in your code beyond that, Raz0r. Lines like these:
include('$panel_tmpl');Things in single quotes aren't parsed. For the variables to be parsed, use double quotes, or in this case, don't use any quotes at all:
include($panel_tmpl);

And a note about Hohoho's comment: Yes, you could use quotes, but there's absolutely no need. Whether you're treating the one as a number or a character it doesn't matter because like Perl, PHP doesn't make a distinction between them for simple comparisons like these.

GregT
November 7th, 2002, 16:02
here my code now




<?
require_once("configfile.php");
require_once("hacks_system.php");
require_once("class_db_connect.php");


$db_connect = new db_connect;
$db_connect->appname="YupaDog Utils";
$db_connect->database=$mysqldb;
$db_connect->server=$mysqlhost;
$db_connect->user=$mysqluser;
$db_connect->password=$mysqlpassword;
$db_connect->connect();


if(!isset($_COOKIE['LoggedIn']))
{
if($panel==1){
include("templates/panel.tmpl");
}

else if($logout==1){
include("templates/logout.tmpl");
}

else if($hostingmailer==1){
include("templates/hostingmailer.tmpl");
}

else if($adminmailsend==1){
include("templates/adminmailsend.tmpl");
}

else {
include("templates/login.tmpl"); }}

function mailsend() {

$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: ".$myname." <".$myemail.">\r\n";
$headers .= "To: ".$contactname." <".$contactemail.">\r\n";
$headers .= "Reply-To: ".$myname." <".$myreplyemail.">\r\n";
$headers .= "X-Priority: 1\r\n";
$headers .= "X-MSMail-Priority: High\r\n";
$headers .= "X-Mailer: Automailer powered by YupaDog Utils v0.001 Alpha";

mail($contactemail, $subject, $message, $headers);

}


if($adminlogin==1){
adminlogin()
}

function adminlogin() {

if(!($link_id = mysql_connect($mysqlhost, $mysqluser, $mysqlpass))) die(mysql_erorr());
mysql_select_db($mysqldb);
$sql = "SELECT ID FROM " . $Table . " WHERE Name='" . addslashes($_POST['Name']) . "' AND Password='" . md5($_POST['Password']) . "' LIMIT 1";
if(!($result = mysql_query($sql))) die(mysql_error());
if(mysql_num_rows($result) == 1) {
setcookie("LoggedIn, TRUE, time()+(3600 * 24)");
echo "Continue to the <a href=index.php?panel=1>Admin Panel</a>";
} else {
echo "Login failure";
}
}

if($adminreg==2){
include("register.htmls");
}

if($adminreg==1){
adminreg()
}
function adminreg() {
if(!($link_id = mysql_connect($sqlhost, $sqluser, $sqlpass))) die(mysql_erorr());
mysql_select_db($sqldb);


$sql = "INSERT INTO " . $Table . " VALUES('', '" . addslashes($_POST['Name']) . "', '" . md5($_POST['Password']) . "')";
if(!($result = mysql_query($sql))) {
die(mysql_error());
} else {

echo "Your user account has been created!<br>";
echo "<a href=index.php>Continues</a> to the login page";
}

?>}

it doesnt work but i'll fix it :o

Kaliber
November 10th, 2002, 23:48
Originally posted by biggulp
if (isset($login)) is recommended over if ($login)

I recommend if(empty($login))

biggulp
November 11th, 2002, 02:25
isset returns true if the variable is set and false if it isn't

GregT
November 11th, 2002, 15:33
right now im just going to use if($login==true) { as i have .htaccess for login :biggrin2: