General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 31st, 2003, 05:53 PM
harvey_r01 harvey_r01 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Bournemouth
Posts: 37 harvey_r01 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Question Session in Frames: why doesn't it work??

Hi all,

Probably a real simple prob for most of you, but...

I have 3 frames (header, navigation and main frame), most of it is static except a search facility and when the link is clicked on a login.php page is invokeed in the main frame. Its a real simple login...

The user types uname + pwd and then it checks your account if valid it will...

PHP Code:
 session_start();
$_SESSION['username'] = $uname;
header("Location:http://www.url_to_search_page.php"); 


The search page includes a file called sess.php which does...

PHP Code:
 session_start();
if (!isset(
$_SESSION['username']))  {
  
// go back to login telling them the session has expired
}  else  {
  
session_start();



The page recognises the users account, tries to goe to the search page but then throws the user back to the login page saying session expired...

Would frames have an impact to the session? I have tried echoing the $_SESSION['username']; on the next page but it outputs nothing??

...Any ideas why?

Cheers,

Harvey

Reply With Quote
  #2  
Old July 31st, 2003, 06:29 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
Quote:
Would frames have an impact to the session? I have tried echoing the $_SESSION['username']; on the next page but it outputs nothing??

You need to make sure that you are passing the SID around between the frames - you can add the sid in the frame src tag:
Code:
src="somepage.php?<?PHP echo( SID ); ?>"

You also need to make sure you are starting the session on the framed pages.
__________________
~ Joe Penn

We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set?

Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you.




Reply With Quote
  #3  
Old August 2nd, 2003, 10:44 PM
harvey_r01 harvey_r01 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Bournemouth
Posts: 37 harvey_r01 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Hi Joe,

thanks for the reply, but I don't understand why the session needs to be started on all pages?? If my main frame is the only frame accessing PHP pages and the other two frames stay static why is there a need to start the session? Sorry, but it would be nice to understand the reasoning...

thanks,

Harvey

Reply With Quote
  #4  
Old August 3rd, 2003, 01:40 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
Quote:
If my main frame is the only frame accessing PHP pages and the other two frames stay static why is there a need to start the session?

Because you still need to append those links in the other frames with the sid to accomodate users that don't have cookies enabled.

If a user does'nt have cookies enabled, and they click a link in one of the static frames that changes the page in the main frame where the interaction of the session is, there is no way that the main frame would know what the session id is unless the link in the static frame passed the sid in the url.

Reply With Quote
  #5  
Old August 3rd, 2003, 09:15 PM
harvey_r01 harvey_r01 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Bournemouth
Posts: 37 harvey_r01 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Cheers Joe,

...but the links on the left pain do not call any other PHP pages or protected pages. The whole site is static bar 1 link which opens a search utility in the mainFrame and the session does not need to be called anywhere else. Please have a look: http://sips.bmth.ac.uk ...and click onto search for placement, and try loging in as uname:test pwd:test

So, in theory if there is only one link to a login page and the other frames do not have any other links to protected PHP pages, it should work?

Thanks,

Harvey

loginpage - when login request sent it does...
PHP Code:
if (isset($_SESSION['username']))  {
  echo 
"<META HTTP-EQUIV=\"Refresh\" CONTENT =\"0;URL=http://www.dynamicwebprojects.co.uk/student/search.placement.php\">";
}

if(
$Login) {
    
$sql "SELECT * FROM smstudents WHERE studuname='" $uname "'";
    
$result mysql_query($sql);
    if (!
$result)  {
      
header("Location: [url]http://www.dynamicwebprojects.co.uk/student/studlogin.php?msg=db404[/url]");
    }
    elseif (@
mysql_num_rows($result) == ( int )0)  {
      
header("Location: [url]http://www.dynamicwebprojects.co.uk/student/studlogin.php?msg=uname404[/url]");
    }
    elseif (@
mysql_num_rows($result) > ( int )0)  {
      
$sql2 "SELECT * FROM smstudents WHERE studuname='" $uname "' AND password='" md5($pwd) . "'";
      
$result2 mysql_query($sql2);
      if (!
$result2)  {
        
header("Location: [url]http://www.dynamicwebprojects.co.uk/student/studlogin.php?msg=db404[/url]");
      }
      elseif (@
mysql_num_rows($result2) == ( int )0)  {
        
header("Location: [url]http://www.dynamicwebprojects.co.uk/student/studlogin.php?msg=staffpwd404[/url]");
      }
      else  {
        
session_start();
        
$_SESSION['username'] = $uname;
        echo 
"<META HTTP-EQUIV=\"Refresh\" CONTENT =\"0;URL=http://www.dynamicwebprojects.co.uk/student/search.placement.php\">";
      }
    }
}

?> 


--Session file included in all other pages does...
PHP Code:
<?php //sess.php
session_start();
if (!isset(
$_SESSION['username']))  {
  
header("Location: [url]http://www.dynamicwebprojects.co.uk/student/studlogin.php?msg=sess404&username=[/url]" urlencode($_SESSION['username']));
}
else  {
session_start();
}    

?>

Reply With Quote
  #6  
Old August 5th, 2003, 08:59 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Harvey,

I'm not an expert on sessions... In fact, I'm learning as I go... In speaking with Joe last week, the reason you still need to append your session id to non-protected pages is so that when your users "resume" their sessions (re-accesses the protected areas), their session will continue from where it left off.

Hope that helps clear the confusion...
__________________
____________________________________________
Developer Shed Weekly Writer | DevArticles Forum Moderator
Build Your Own KlipFolio Klip With PHP
FrankManno.com - Under Construction
Design Interactive Group - Under Construction

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Session in Frames: why doesn't it work??


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway