Jump to content

[SOLVED] Wtf.. my if...else include isn't doing anything


bloodgoat

Recommended Posts

CFG.PHP

<?php

$fpath = "path/to/site/etc";

if($action == ""){
if(!isset($_COOKIE['user']) && !isset($_COOKIE['pass']) && !isset($_COOKIE['addr'])){ 
	$title = "Log In";
	include($fpath."/login.php");
}
else {
	$title = "Main Panel";
	include($fpath."/admin_panel.php");
}
}
elseif($action == "login"){
include($fpath."/check_login.php");
}

?>

Problem: it fetches the "login.php" file just fine. But if I go to index.php?action=login, it doesn't fetch "check_login.php", it just keeps displaying "login.php". I thought it might have been because I was compounding one if statement inside of the other (for some reason, doing this always leads me to trouble) but even after making a separate file for the if...else statements within $action="", and including it, nothing changed.

 

If it matters, here are a couple of my other files (the above being CFG.PHP):

 

INDEX.PHP

<?php

include("cfg.php");

$template = <<< html
<head>
<title>EXOSPHERE -$title</title>
</head>
<link rel="stylesheet" type="text/css" href="style.css">
<script language="JavaScript" src="expand.js"></script>
<body bgcolor="#f9e6b3" marginwidth="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<div class="spacer"></div>

$content

</body>
</html>
html;

echo $template;

?>

 

LOGIN.PHP

<?php

$content = <<< html
<form action="check_login.php" method="post">
<table border="0" cellpadding="4" cellspacing="0" width="900" align="center">
<tr>
	<td class="title" height="35">$title</td>
</tr>
<tr>
	<td class="spacer"></td>
</tr>
<tr>
	<td class="ndate">Username</td>
</tr>
<tr>
	<td class="nnews"><input type="text" name="username" class="input" size="40"></td>
</tr>
<tr>
	<td class="ndate">Password</td>
</tr>
<tr>
	<td class="nnews"><input type="password" name="password" class="input" size="40"></td>
</tr>
<tr>
	<td height="35"><input type="submit" value="Log In" class="input"></td>
</tr>
</table>
</form>
html;

?>

(No actual PHP, I know, it's just to stick to the format, though.)

 

CHECK_LOGIN.PHP

<?php

include("users.php");

foreach($users as $key => $user){
$user_level = $user[2];
if($_POST['username'] == $user[0] && $_POST['password'] == $user[1]){
	$usrName = $_POST['username'];
	$usrPass = $_POST['password'];
	$usrAddr = $_SERVER['REMOTE_ADDR'];
   		setcookie('user', $usrName, time()+60*60);
    	    	setcookie('pass', $usrPass, time()+60*60);
     	   	setcookie('addr', $usrAddr, time()+60*60);
	setcookie('levl', $user_level, time()+60*60);
	$title = "Log In Successful";
	$content = "Successfully logged in!<br>\n";
	$content .= "You have been logged in as <b>".$usrName."</b>.<br>\n";
		if($user_level == "3"){$content .= "Your user level is <b>".$user_level."</b>, you are an administrator.<br>\n";}
		elseif($user_level == "2"){$content .= "Your user level is <b>".$user_level."</b>, you are a moderator.<br>\n";}
		elseif($user_level == "1"){$content .= "Your user level is <b>".$user_level."</b>. This is a demonstration account.<br>\n";}
	$content .= "<a href=\"index.php\">Continue</a> to the admin panel";
	break;
}
}

if($_POST['username'] != $user[0] || $_POST['password'] != $user[1]){
$title = "Log In Failed";
$content = "You have entered invalid credentials. Please try again.<br>\n";
$content .= "<a href=\"javascript:history.go(-1);\">Return</a>";
}

?>

Just wondering because I tried the way I just mentioned and nothing happened, still, which I found preposterous, because I use that very method on my main site and it works perfectly. Regardless, I just chose to use your method. It's working now. For something so laughably easy, it had me stumped pretty bad.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.