programguru Posted January 30, 2009 Share Posted January 30, 2009 I am writing a simple login script, and I am trying to keep my logic and structure separate. But it seems my method is a bit clunky. I am using require_once() (as you can see below) to pull in the form and admin links page based on the login authentication and session. The main questions I have are: 1) is there a better method of pulling in the structure pages? 2) why is there a "1" showing the results of either require when the structure is pulled in? I assume the "1" just means the require was successful and thus "true". But it seems goofy to show that on result. <?php //start session session_start(); // check if the user is coming from the form if ($_POST[op] == "ds") { // check username and password if (($_POST[username] != "234") || ($_POST[password] != "234")) { // bad login message $msg = "Please enter the correct username and password."; $show_form = "yes"; } else { // handle good login $_SESSION[valid] = "yes"; $show_menu = "yes"; } } else { // determine what to show if ($valid == "yes") { $show_menu = "yes"; } else { $show_form = "yes"; } } if ($show_form == "yes") { $display_block = require_once('secure_login.php'); } else if ($show_menu == "yes") { $display_block = require_once('admin_menu.php'); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>TEST ADMIN CONSOLE</title> </head> <body> <?php echo "$display_block"; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/143070-solved-require-or-include-if-page-for-view-showing-1-as-true-is-there-a-better-method/ Share on other sites More sharing options...
Philip Posted January 30, 2009 Share Posted January 30, 2009 Well, you're setting display_block to be the return value of require_once - which means it will return 1 on successful , 0 on a failure. I'd suggest you look a little more into how require/include works. Quote Link to comment https://forums.phpfreaks.com/topic/143070-solved-require-or-include-if-page-for-view-showing-1-as-true-is-there-a-better-method/#findComment-750341 Share on other sites More sharing options...
programguru Posted January 30, 2009 Author Share Posted January 30, 2009 Well, you're setting display_block to be the return value of require_once - which means it will return 1 on successful , 0 on a failure. I'd suggest you look a little more into how require/include works. KingPhilip, Thanks for the note. That's what I assumed as well. But I was looking for more a suggestion as to avoiding a require or include and still keeping the structure seperate as opposed to embedding the html forms in php. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/143070-solved-require-or-include-if-page-for-view-showing-1-as-true-is-there-a-better-method/#findComment-750344 Share on other sites More sharing options...
programguru Posted January 30, 2009 Author Share Posted January 30, 2009 I figured out another way!!! Quote Link to comment https://forums.phpfreaks.com/topic/143070-solved-require-or-include-if-page-for-view-showing-1-as-true-is-there-a-better-method/#findComment-750368 Share on other sites More sharing options...
Philip Posted January 30, 2009 Share Posted January 30, 2009 Our of curiosity, what did you end up going with? Quote Link to comment https://forums.phpfreaks.com/topic/143070-solved-require-or-include-if-page-for-view-showing-1-as-true-is-there-a-better-method/#findComment-750393 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.