dr.maju Posted July 20, 2008 Share Posted July 20, 2008 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 More sharing options...
Goldeneye Posted July 20, 2008 Share Posted July 20, 2008 Hmmm try changing this: <?php $member = $_GET['$member']; ?> To this: <?php $member = $_GET['member']; ?> Link to comment https://forums.phpfreaks.com/topic/115741-solved-php-sessions-please-help/#findComment-594996 Share on other sites More sharing options...
Lodius2000 Posted July 20, 2008 Share Posted July 20, 2008 <?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 Link to comment https://forums.phpfreaks.com/topic/115741-solved-php-sessions-please-help/#findComment-594999 Share on other sites More sharing options...
marklarah Posted July 20, 2008 Share Posted July 20, 2008 Pro tip: try avoid making websites with iframes unless you absolutely have to. Link to comment https://forums.phpfreaks.com/topic/115741-solved-php-sessions-please-help/#findComment-595024 Share on other sites More sharing options...
dr.maju Posted July 21, 2008 Author Share Posted July 21, 2008 Hey thanks for the comments. It's now working a bit better, but the clients/client1.php pages dont come up, i just get my hosts 404 error page. Could the problem be with the login code? Do i save the member_id to the session correctly? Thanks again, Matt Link to comment https://forums.phpfreaks.com/topic/115741-solved-php-sessions-please-help/#findComment-595323 Share on other sites More sharing options...
samshel Posted July 21, 2008 Share Posted July 21, 2008 echo out the id for debugging...if it is coming wrong, correct it and if it is coming correct, then make sure your client directory is in the directory as your script. Link to comment https://forums.phpfreaks.com/topic/115741-solved-php-sessions-please-help/#findComment-595329 Share on other sites More sharing options...
dr.maju Posted July 21, 2008 Author Share Posted July 21, 2008 Hey thanks. Yes the right user id comes up when i echo out $member. So i guess that means the sessions working. Any idea on what could be wrong. Thanks for all ure help! Link to comment https://forums.phpfreaks.com/topic/115741-solved-php-sessions-please-help/#findComment-595335 Share on other sites More sharing options...
dr.maju Posted July 21, 2008 Author Share Posted July 21, 2008 YAY!! it worked!! I didn't include an else(); after the if statements. After doing that it worked so THANKYOU ALL! Link to comment https://forums.phpfreaks.com/topic/115741-solved-php-sessions-please-help/#findComment-595336 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.