Jump to content

if statement inside if statement not working


HDFilmMaker2112
 Share

Recommended Posts

I'm having issues with the following:

 

<?php
session_start();
$_SESSION['username']=$_POST['username'];
$_SESSION['password']=$_POST['password'];
if($_SESSION['username']=="username" && $_SESSION['password']=="password"){
if($_GET['product']=="add"){
$content.='
<p><label>Product Name:</label> <input type="text" name="product_name" size="30" />
<label>Product Price:</label> <input type="text" name="product_price" size="5" />
</p>
<p><label>Product Category:</label> <input type="text" name="product_category" size="30" /></p>
<p><label>Product Link:</label> <input type="text" name="product_link" size="30" /></p>
<p><label>Product Image:</label> <input type="text" name="product_image" size="30" /></p>
<p><label>Product Tag:</label> <input type="text" name="product_tag" size="30" /></p>
<p><label>Product Keywords:</label> <input type="text" name="keyword" size="30" /></p>
<p><label>Product Features:</label><br />
<textarea name="product_features" rows="10" cols="60"></textarea>
</p>
<p><label>Product Pros:</label><br />
<textarea name="product_pros" rows="5" cols="30"></textarea>
</p>
<p><label>Product Cons:</label><br />
<textarea name="product_cons" rows="5" cols="30"></textarea>
</p>
<p><label>Product Description:</label><br />
<textarea name="product_description" rows="10" cols="60"></textarea>
</p>
<p><label>Product Notes:</label><br />
<textarea name="product_notes" rows="5" cols="30"></textarea>
</p>
';
$logout='<div><a href="./acp_admincp.php?log-out">Log-Out</a></div>';
}
elseif($_GET['product']=="view"){
}
else{
$content.='
<a href="./admincp.php?product=add">Add New Product</a>
<br />
<a href="./admincp.php?product=view">View Products</a>
';
}
}
elseif(isset($_GET['log-out'])){
session_start();
session_unset();
session_destroy();
header("Location: ./admincp.php");
}
else{
$content='
<form action="./admincp.php" method="post">
<p><label>Username:</label> <input type="text" name="username" size="30" />';
$content.='</p>
<p><label>Password:</label> <input type="password" name="password" /></p>';
$content.='<p><input type="submit" value="Submit" name="Submit" /></p>
</form>';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 
<head>
<base href="http://ghosthuntersportal.com/" />
<title>Ghost Hunter's Portal - Admin Control Panel</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="verify-v1" content="" />
<meta name="keywords" content="ghost, hunters, hunter, ghosts, spirit, spirits, paranormal, investigation, investigator, investigators, k2, emf, meter, kii" />
<meta name="description" content="Ghost Hunters Potal. Parnormal research equipment store." />
<meta name="author" content="Andrew McCarrick" />
<meta name="robots" content="index, follow" 
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<img src="./logo.png" alt="Ghost Hunter's Portal Admin Control Panel" />
<br />
<div style="color: #AA44AA; font-size: 26px; margin-top: -30px; margin-left: 125px;">Admin Control Panel</div>
<?php
echo $logout;
echo $content;
?>
</body>
</html>

 

I can log-in, and get to the page with the two links on it. However, once I click one of the links it falls back to the log-in page, and it ends up being a never ending loop.

 

It's doing this:

Log-In --> Page with links ---> Log-In page again

 

Should be doing this:

Log-In --> Page with links --> Add Product page or View Products page

 

I can never get into the the actual sub page.

 

Just to be clear, the address bar actually shows product=add or product=view, but it still shows the log-in page.

Link to comment
Share on other sites

This code

$_SESSION['username']=$_POST['username'];
$_SESSION['password']=$_POST['password'];

 

will overwrite the session data as soon as you access another page.  You should put another "if" around it to check if the login form is being submitted.

Link to comment
Share on other sites

Actually... never mind, no I didn't.

 

What should I be doing exactly. I tried a few different things; including putting an if statement just around the $_SESSION

 

i.e;

if($_POST['username']=="username" && $_POST['password']=="password"){
$_SESSION['username']=$_POST['username'];
$_SESSION['password']=$_POST['password'];
}

that made it work except the log-out portion was no longer working. So what exactly should I be doing and where should I be placing it to keep everything functioning?

Link to comment
Share on other sites

This thread is more than a year old.

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.

 Share

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