Jump to content

[SOLVED] PHP Sessions - PLEASE HELP!


dr.maju

Recommended Posts

Hey,

 

I am a true rookie at php and any help will be greatly appreciated. On my page i have an iFrame. I would like the SRC of the iFrame to change based on what user is logged on. In my login page (which works fine), i create a session that stores the logged in members id (that is stored in the database) at least i think i do! Then in the iFrame, i try to recall this data and use if(); statements to create the SRC.

 

The login that stores member_ id to the session:

 

<?php
//Start session
session_start();

//Connect to Database
$dbh=mysql_connect ("localhost", "MYUSERNAME",
"MYPASSWORD") or die('Cannot connect to the database because: ' . mysql_error());
mysql_select_db ("trinity_clients");

//Sanitize the value received from login field
//to prevent SQL Injection
if(!get_magic_quotes_gpc()) {
	$login=mysql_real_escape_string($_POST['login']);
}else {
	$login=$_POST['login'];
}

//Create query
$qry="SELECT member_id FROM members WHERE login='$login' AND passwd='".md5($_POST['password'])."'";
$result=mysql_query($qry);
//Check whether the query was successful or not
if($result) {
	if(mysql_num_rows($result)>0) {
//Login Successful
		session_regenerate_id();
		$member=mysql_fetch_assoc($result);
		$_SESSION['SESS_MEMBER_ID']=$member['member_id'];
		session_write_close();
		header("location: login_success.php");

	}else {
//Login failed
		header("location: login_unsuccessful.html");
		exit();
	}
}else {
	die("Query failed");
}
?>

 

The iFrame code:

 

<iframe height="650" width="1024" style="border:none;" src=
"
<?php
session_start();
   //check session
$_SESSION['SESS_MEMBER_ID']; 
$member = $_GET['$member'];
   
   if($member == 1)
   
{
echo "clients/client1.php";
}

   if($member == 2)
{
echo "clients/client2.php";
}

   if($member == 3)
{
echo "clients/client3.php";
}

   if($member == 4)
{
echo "clients/client4.php";
}
?>
">
</iframe>

 

Sorry if thats all a bit vague. Thankyou!

Link to comment
https://forums.phpfreaks.com/topic/115741-solved-php-sessions-please-help/
Share on other sites

 

<?php
session_start();
if ($_SESSION['SESS_MEMBER_ID']){ 
$member = $_SESSION['SESS_MEMBER_ID']; //changed this from get method, to use session data
  
  if($member == 1)
  
{
echo "clients/client1.php"; //if you want this to automatically redirect to client1.php use 
                                      // header('Location: clients/client1.php');
}

  if($member == 2)
{
echo "clients/client2.php";
}

  if($member == 3)
{
echo "clients/client3.php";
}

  if($member == 4)
{
echo "clients/client4.php";
}
} else {
//print code to login
}
?>

 

untested but i think it will work

Archived

This topic is now archived and is closed to further replies.

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