Dropped session data

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm having problems with setting session data from inside an iframe. I have the
main page then you click on the log in button to change the iframe over to a
login box. Once you login I should beable to refresh the main page and the log
in button should change to a log out button.

If you would like to help me directly that would be great. Contact me via IM
anytime.

AIM: Gryphon4200
YIM: Gryphon4200

================ index.php =========================

<?php

  if(session_id() == "")
  {
  	session_start();
	$logged_in=0;
	$_SESSION['username'] = "Anonymous";
	$_SESSION['password'] = "";
	$username=$_SESSION['username'];
	$password=$_SESSION['password'];

  } else {

	$logged_in=1;
	$username=$_SESSION['username'];
	$password=$_SESSION['password'];
  }

/*
  echo "<font color='#ffffff'>";
  var_dump($_SESSION);
  echo "</font>\n\n";
*/
?>

<html>
<head><title>Albright Booking - test site</title></head>

<link rel="stylesheet" type="text/css" href="style.css">

<body>
	
<table class='main' align='center' width="800" height="1024" border="1"
cellpadding="0" cellspacing="0">
	<tr class='header' height='120'>
		<td colspan='6' align="center">Albright Booking</td>
	</tr>
	<tr class='nav'>
		<td align="center" height="23"><a href='news.php'
target='contentarea'>Home</a></td>
		<?php
			if($logged_in==1)
			{
				echo "<td align='center' width='133'><a href='Scripts/logout.php'
target='contentarea'>Log out</a></td>";
			} else {
				echo "<td align='center' width='133'><a href='Scripts/login.php'
target='contentarea'>Log in</a></td>";
			}
		?>
		<td align="center" width='133'><a href='events.php'
target='contentarea'>Events</a></td>
		<td align="center" width='133'><a href='links.html'
target='contentarea'>Links</a></td>
		<td align="center" width='133'><a href='aboutus.html'
target='contentarea'>About us</a></td>
		<td align="center" width='133'><a href='contactus.html'
target='contentarea'>Contact Us</a></td>
	</tr>
	<tr class='content' valign='top' align='center'>
		<td colspan="6"><iframe frameborder='1' src='news.php' name='contentarea'
width='798' height='830'></iframe></td>
	</tr>
	<tr height='50' class='footer' valign='bottom'>
		<td colspan="6" align='right'>Gryphon Computer Systems <br> Albright Booking
<br> Copyright 2006</td>
	</tr>
</table>

</body>

</html>

================== login.php =========================

<?php

// database connect script.

require 'db_connect.php';

if($logged_in == 1)
{
	die('You are already logged in, '.$_SESSION['username'].'.');
}

?>

<html>
<head><title>Login</title></head>
<body>

<?php

if (isset($_POST['submit']))  // if form has been submitted
{
	/* check they filled in what they were supposed to and authenticate */

	if(!$_POST['uname'] | !$_POST['passwd'])
       	{
		die('You did not fill in a required field.');
	}

	// authenticate.

	if (!get_magic_quotes_gpc())
	{
		$_POST['uname'] = addslashes($_POST['uname']);
	}

	$query = "SELECT * FROM users WHERE username='".$_POST['uname']."'";

	$lookup = mysql_query($query);

	$row = mysql_fetch_object($lookup);

	$tmpuname=$row->username;

	if ($tmpuname != $_POST['uname'])
	{
		die('User does not exsit.');
	
	} else {
	  // check passwords match

	  $_POST['passwd'] = stripslashes($_POST['passwd']);
	  $info['password'] = stripslashes($info['password']);
	  $_POST['passwd'] = md5($_POST['passwd']);
	  
	  if ($_POST['passwd'] != $row->password)
	  {
		  die('Incorrect password, please try again.');
	  }	
	}	
	
	// if we get here username and password are correct, 

	//register session variables and set last login time.

	$date = date('m d, Y');

	$update_login = mysql_query("UPDATE users SET last_login = '$date' WHERE
username = '".$_POST['uname']."'");

	$_POST['uname'] = stripslashes($_POST['uname']);

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

	$logged_in=1;
	
mysql_close();

?>

<h1>Logged in</h1>
<p>Welcome back <?php echo $_SESSION['username']; ?>, you are logged in.</p>
<br>
<br>
<?php var_dump($_SESSION); ?>

<?php

} else {	// if form hasn't been submitted

?>

<h1>Login</h1>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<table align="center" border="1" cellspacing="0" cellpadding="3">
<tr><td>Username:</td><td>
<input type="text" name="uname" maxlength="40">
</td></tr>
<tr><td>Password:</td><td>
<input type="password" name="passwd" maxlength="50">
</td></tr>
<tr><td colspan="2" align="right">
<input type="submit" name="submit" value="Login">
</td></tr>
</table>
</form>
<?php
}
?>
</body>
</html>

Yahoo ID: Gryphon4200
AIM Name: Gryphon4200
gryphon4200@xxxxxxxxx
http://www.myspace.com/gryphon4200

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


PHP Data object relational mapping generator
http://www.metastorage.net/ 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-objects/

<*> To unsubscribe from this group, send an email to:
    php-objects-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux