Jump to content

Log in-out strange redirection with iframes


willowone

Recommended Posts

I have a simple log in-out button using sessions.The code is in the end and everything works fine but when i log in,the main.php is being opened in another page and when i try to log out from this one the results are shown in the previous window!If this is closed by me it opens again another one!!I guess the mistake is somewhere in my form but i cant figure where, i could really appreciate some help!

 

And here is the code for the main page and the top iframe:

Top.php

 

<?php
session_start();
    $hostname="localhost"; //we define a variable
$username="root"; //we define a username
$password=""; //we define a password
$dbname="main"; // we define a db name
$cont=mysql_connect($hostname,$username,$password);
if($cont !=false){
	if(!mysql_select_db($dbname,$cont)) {
	echo "can not connect to database";
	}
} 	
?>
<!DOCTYPE html> 
<html lang="en">
<head>
</head>
<body>
<?php
if(isset($_SESSION['loggedin']))
    {
echo"You are already logged in!<a href=\"main.php?logout=1\" target=\"main\">Log out!</a>";
   
}
else {
echo "UserName :           Password:</keimenoC>";
echo "<form action=\"main.php\" method=\"post\" target =\"main.php\"><formaA>";
echo "<input type=\"text\" size=\"12\" name=\"username\" >";
echo "<input type=\"password\" size=\"12\" name=\"password\"></formaA>";
echo "<formaAButton><input type=\"image\" src=\"login.bmp\" VALUE=\"Login\" /></formaAButton>";
echo "</form>";
  // echo "<form type='main.php' method='POST'>
  // Username: <br>
  // <input type='text' name='username'><br>
  // Password: <br>
  // <input type='password' name='password'><br>
  // <input type='submit' name='submit' value='Login'>
  // </form>"; // That set up the form to enter your password and username to login.
   }
?>
</body>
</html>

 

and for the main.php

 

<?php
session_start();
//session_destroy();
if($_GET["logout"] == 1){unset($_SESSION['loggedin']);}

$hostname="localhost"; //we define a variable
$username="root"; //we define a username
$password=""; //we define a password
$dbname="main"; // we define a db name
$cont=mysql_connect($hostname,$username,$password);
if($cont !=false){
	if(!mysql_select_db($dbname,$cont)) {
	echo "can not connect to database";
	}
} 	
if($_POST["username"] && $_POST["password"])
{
   $name = mysql_real_escape_string($_POST['username']); // The function mysql_real_escape_string() stops hackers!
   $pass = mysql_real_escape_string($_POST['password']); // We won't use MD5 encryption here because it is the simple tutorial, if you don't know what MD5 is, dont worry!
   $mysql = mysql_query("SELECT * FROM users WHERE username = '{$name}' AND password = '{$pass}'"); // This code uses MySQL to get all of the users in the database with that username and password. 
   
   while($rowLogin = mysql_fetch_array($mysql)){
   $_SESSION['loggedin'] = "YES";
   $_SESSION['name'] = $name; // Make it so the username can be called by $_SESSION['name']
   }
   }
?>

<!DOCTYPE html> 
<html lang="en"> 
<head> 
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
	<title>TEST! </title> 
	<link rel="stylesheet" type="text/css" media="screen" href="styles.css" /> 
</head> 
<body>		
	<iframe id="header" frameborder = "0" height = "100" width = "1350" src="top.php" </iframe> 	
	<iframe id="draggableNodes" frameborder = "0" height = "900" width = "250" src="draggableNodesFrame.php"></iframe> 
	<iframe name="middle" id="middle" frameborder = "0" height = "900" width = "800" src="middle.php"></iframe> 
	<iframe id="dropTargets" frameborder = "0" height = "900" width = "250" src="dropTargetFrame.php"></iframe> 
	<iframe id="bottom" frameborder = "0" height = "100" width = "1350" src="bottom.html"></iframe> 		
</body> 
</html> 

Link to comment
Share on other sites

As i see it,my problem is here:

 

echo "<form action=\"main.php\" method=\"post\" target =\"main.php\"><formaA>";

 

The target is not another iFrame but the whole page,and for this it opens it in a new window every time.How can i say that i want my tarhet to be in the same window?!?  :D

Link to comment
Share on other sites

I'm trying to understand. Okay, assuming main.php is in a frame and you want the form to submit in the upper 'parent' document then target="_parent"

 

echo "<form action=\"main.php\" method=\"post\" target =\"_parent\">

 

Or if you wanted it to load in your frame named "middle"

 

echo "<form action=\"main.php\" method=\"post\" target =\"middle\">

 

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.