willowone Posted July 20, 2010 Share Posted July 20, 2010 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 https://forums.phpfreaks.com/topic/208278-log-in-out-strange-redirection-with-iframes/ Share on other sites More sharing options...
willowone Posted July 20, 2010 Author Share Posted July 20, 2010 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?!? Link to comment https://forums.phpfreaks.com/topic/208278-log-in-out-strange-redirection-with-iframes/#findComment-1088512 Share on other sites More sharing options...
TheEvilMonkeyMan Posted July 20, 2010 Share Posted July 20, 2010 If you don't specify a target on your form then it will load in the same frame. Otherwise specify a frame's name and it will load inside that frame. Link to comment https://forums.phpfreaks.com/topic/208278-log-in-out-strange-redirection-with-iframes/#findComment-1088513 Share on other sites More sharing options...
willowone Posted July 20, 2010 Author Share Posted July 20, 2010 I know,but now i want to target to the main page that has all the iframes,including the one sending the posts. If i put target="main.php" it opens it in a new window which is no good... Link to comment https://forums.phpfreaks.com/topic/208278-log-in-out-strange-redirection-with-iframes/#findComment-1088515 Share on other sites More sharing options...
TheEvilMonkeyMan Posted July 20, 2010 Share Posted July 20, 2010 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 https://forums.phpfreaks.com/topic/208278-log-in-out-strange-redirection-with-iframes/#findComment-1088516 Share on other sites More sharing options...
willowone Posted July 20, 2010 Author Share Posted July 20, 2010 _parent was the solution TheEvilMonkeyMan, thanks very very very much for your help and your time!Problem solved! Link to comment https://forums.phpfreaks.com/topic/208278-log-in-out-strange-redirection-with-iframes/#findComment-1088517 Share on other sites More sharing options...
TheEvilMonkeyMan Posted July 20, 2010 Share Posted July 20, 2010 No problem Link to comment https://forums.phpfreaks.com/topic/208278-log-in-out-strange-redirection-with-iframes/#findComment-1088519 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.