Jump to content

[SOLVED] require or include if page for view showing "1" as true is there a better method


Recommended Posts

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>

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.

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.