Jump to content

function within a if statement


sanson06

Recommended Posts

i don't understand what you mean so here is my code:

 

<div style=" margin:auto; width:800px;">


<div style="float:left; width:800px; text-align:center; background:#000; color:#FFF;">
<h1>HEADER</h1>
</div>
<div style="float:left; width:200px; text-align:center; background:#333; color:#FFF; clear:right;">
<h1>Left</h1>
</div>
	I want to call funtion HERE
<div style="float:right; width:100%; text-align:center; background:#666; color:#FFF; clear:righ;">
<?php		// Beginning of password script
$password = "admin";  // Change Password to your need
?>
<?php 
// If the password is valid user gets access
if (isset($_POST["password"]) && ($_POST["password"]=="$password")) {
function funtTest1(){
$hide1 = "hi 1";
echo $hide1;
}
function funtTest(){
$hide2 = "hi 2";
echo $hide2;
}
?>
<!-- Start of hidden content -->


<br />
<span class="entry_title">title</span>


<!-- End of hidden content -->

<?php 
}
else
{

// If wrong password or no password
if (isset($_POST['password']) || $password == "") {
  print "<p align=\"center\"><font color=\"red\"><b>Incorrect Password</b><br>Please enter the correct password</font></p>";}
print "<form method=\"post\"><p align=\"center\">Please enter your password for access<br>";
  print "<input name=\"password\" type=\"password\" size=\"25\" maxlength=\"10\"><input value=\"Login\" type=\"submit\"></p></form>";
}
?>

</div>

<div style="float:left; width:100%; clear:both; text-align:center; background:#999; color:#FFF;">
<h1>FOTTER</h1>
</div>


</div>

Link to comment
Share on other sites

Defining a function is different than invoking a function.  When you write:

 

function myFunc($arg1)
{
   // do something with $arg1
}

 

You're not actually running (invoking) the function at that point.  You're merely defining it.  All you're really doing is telling the script "Here's a custom function I wrote."

 

It makes sense to define functions outside of your script's execution flow in order to keep this distinction clear.  Function definitions can still be placed in the same file as your script, but they don't belong in conditionals or loops.

Link to comment
Share on other sites

It's as simple as (pseudo-code):

 

if (/* entered password is NOT correct */)
{
   // display side bar
}

 

There's no else-clause because I'm assuming that the default state of the page wouldn't have the side bar.

 

Now, you'll have to figure out how to check that the user is logged in, how to pass that info from page to page, and how to display the side bar itself.

Link to comment
Share on other sites

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.