bloodgoat Posted March 25, 2009 Share Posted March 25, 2009 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>"; } ?> Link to comment https://forums.phpfreaks.com/topic/151130-solved-wtf-my-ifelse-include-isnt-doing-anything/ Share on other sites More sharing options...
PHP Monkeh Posted March 25, 2009 Share Posted March 25, 2009 If you don't have global variables enabled on your web server (and you shouldn't) - you'll need to replace $action with $_GET['action'] or put at the top of your code: $action = $_GET['action'] Link to comment https://forums.phpfreaks.com/topic/151130-solved-wtf-my-ifelse-include-isnt-doing-anything/#findComment-793929 Share on other sites More sharing options...
bloodgoat Posted March 25, 2009 Author Share Posted March 25, 2009 Would that be at all similar (in the way it functions) to something like... if(!isset($action)){ include($fpath."/login.php"); } elseif(isset($action)){ include($fpath."/".$_GET['action'].".php"); } Link to comment https://forums.phpfreaks.com/topic/151130-solved-wtf-my-ifelse-include-isnt-doing-anything/#findComment-793930 Share on other sites More sharing options...
PHP Monkeh Posted March 25, 2009 Share Posted March 25, 2009 You could use it like that yeah, except you'll need to change the $action in your isset() function as well. If you put $action = $_GET['action'] at the top of your code you can then use $action afterwards. Link to comment https://forums.phpfreaks.com/topic/151130-solved-wtf-my-ifelse-include-isnt-doing-anything/#findComment-793931 Share on other sites More sharing options...
bloodgoat Posted March 25, 2009 Author Share Posted March 25, 2009 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. Link to comment https://forums.phpfreaks.com/topic/151130-solved-wtf-my-ifelse-include-isnt-doing-anything/#findComment-793937 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.