Link to home
Start Free TrialLog in
Avatar of MsKrissy
MsKrissy

asked on

div parent page load

I have the following code that logs the user in, the only issue is the script is in a div, so when it loads the contents needed, it loads it within that same div instead of loading it on the parent level.  
Help Please!

This is the login page that holds the div
<body>

<table  border="0" cellpadding="0" cellspacing="0" hspace="0">
<tr>
  <td><table  border="0" cellpadding="0" cellspacing="0" hspace="0">
    <tr>
      <td><img src="images/login.png" border="0" usemap="#Map"></td>
    </tr>
  </table></td>
</tr>
</table>

<div class="login" style="left:757px; top:190px; overflow:no;">
<object data="scripts/login_field.html" type="text/html" name="foo" width="460" height="195" id="foo" style="width:460px; height:150px;"></object>
</div>
</body>

Open in new window



Here is the actual form
</head>

<body>
<table width="300" border="0" align="left" cellpadding="0" cellspacing="1">
<tr>
<form name="form1" method="post" action="checklogin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1">
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78" align="right">Email</td>
<td width="6">:</td>
<td width="294"><input name="email1" type="text" id="email1"></td>
</tr>
<tr>
<td align="right">Password</td>
<td>:</td>
<td><input name="password1" type="password" id="password1"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</body>

Open in new window

Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

This javascript will push the PHP page to the parent frame but you can see it move.  I assume you have more code on those pages or you wouldn't be doing this this way.  I don't know how to make it open first in the parent window.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>checklogin.php</title>
<script type="text/javascript">
<!--
function breakout_of_frame()
{
  if (top.location != location) {
    top.location.href = document.location.href ;
  }
}
// -->
</script>
</head>
<body onload="breakout_of_frame()">
<h1>checklogin.php</h1>
</body>
</html>

Open in new window

Avatar of MsKrissy
MsKrissy

ASKER

I do have other code on these pages.  I have added the code you offered, here is how I have it implemented.  Let me know if this is correct, because I am still getting the same results:

<?php
include_once "connections/connect_to_mysql.php";
		 
		$id = 'id';
		$username = 'username';
		$email1 = 'email1';

// username and password sent from form
   		$email1 = $_POST['email1'];
        $password1 = $_POST['password1'];


// To protect MySQL injection
         $email1=strip_tags($email1);
		 $email1=mysql_real_escape_string($email1);
		 $email1=eregi_replace("'","",$email1);
		 
         $password1=strip_tags($password1);
         $password1=mysql_real_escape_string($password1);
         $password1=eregi_replace("'","",$password1);
         $password1=md5($password1);


$sql = mysql_query("SELECT * FROM userreg WHERE email1='$email1' AND password1='$password1'"); 
         $login_check=mysql_num_rows($sql);
       
        if ($login_check != 0){
while($row = mysql_fetch_array($sql)){
		// Set a session variable for their ID
		$id = $row["id"]; 
		session_register('id'); // Register the session variable's id
		$_SESSION['id'] = $id; // Put the value you want in that session variable

		// Set a session variable for their username
		$username = $row["username"]; 
		session_register('username'); // Register the session variable's username
		$_SESSION['username'] = $username; // Put the value you want in that session variable

		// Set a session variable for their name
		$email1 = $row["email1"]; 
		session_register('email1'); // Register the session variable's email
		$_SESSION['email1'] = $email1; // Put the value you want in that session variable
		
        mysql_query("UPDATE userreg SET last_log_date=now() WHERE username='$username'"); 
    } // close while
	
header("location:../main.php");
}
else {
echo "Wrong Username or Password";
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>checklogin.php</title>
<script type="text/javascript">
<!--
function breakout_of_frame()
{
  if (top.location != location) {
    top.location.href = document.location.href ;
  }
}
// -->
</script>
</head>
<body onload="breakout_of_frame()">
<h1>checklogin.php</h1>
</body>
</html>

Open in new window



The login.html calls the form from the login_field.html file, and the checklogin.php is the logic.
Okay,
I misspoke, it does work if the user puts in the incorrect username or password.  But it doesn't work if they put in the correct information.
Yep, that's the way it works.  I did prototype it with those file names.
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you for the help, I will research how to get the page to load without loading the frame first.