Jump to content


Please help....Online Classroom Protect snippet


2 replies to this topic

#1 Jared

    Etomite Forum Newbie

  • Member
  • 1 posts

Posted 02 January 2008 - 07:28 PM

Good Afternoon.

I am new at this so please be patient. I need a very simple snippet to have one "login" page that redirects to a number of different "classroom" pages based on the login info. The problem that I currently have is that I cannot figure out how to pull the page id out of the array of information. (example: [[OnlineClassroomProtect?login1=name1|40&login2=name2|50]])

How do I get this to redirect to page 50 when "name2" is entered?
As you can see by the code below my temporary fix was to match the classroom names to pages with a furl specified. (I know it's ugly...but it works for the moment.)

Any help is greatly appriciated.

Thanks in advance,
Jared

 // Based on the SimplePasswordProtect snippet.
 // usage (sample for 2 classrooms):
 // insert in the login page (25=login page & 40,50=classroom pages): [[OnlineClassroomProtect?login1=name|40&login2=name|50]]
 // insert in the content page [[OnlineClassroomProtect?pageid=40&loginpage=25]]
 
 
 session_start();
 session_register('authenticated');
 
 $currentpage=$etomite->documentObject['id'];
 if(!isset($loginpage)) $loginpage=$currentpage;
 
 
 // login form
 $passwordform = "";
 $passwordform .= '<p>This is a protected area of the website.
 ';
 $passwordform .= 'What Classroom would you like to enter?
 ';
 $passwordform .= '<form action="[~'.$loginpage.'~]" method="post">';
 $passwordform .= 'Classroom: 
 <input type="text" name="post_classroom" />';
 $passwordform .= '<input type="submit" value="Go" />';
 $passwordform .= '</form></p>';
 
 if(isset($pageid)) {
	 // logged in with right pageid
	 if($_SESSION['authenticated']) return "";
	 
	 // not logged in and current page is not loginpage
	 if($loginpage!=$currentpage) {
		 Header('Location: '.$etomite->rewriteUrls('[~'.$loginpage.'~]'));
		 exit;
		 //return "??";
	 }
	 
	 // not logged in and this is login page
	 return "<hr />".$_SESSION['authenticated']." :: ".$pageid."<hr />".$passwordform;
	 
 }
 
 // Reading the list of classroom
 for($i=1;$i<=100;$i++) {
	 if(isset(${'login'.$i})) {
		 list($k1,$v)=split("\|",${'login'.$i});
		 $login[$k1]=$v;
	 } else break;
 }
 if(!isset($login)) return 'not enough parameters';
 
 
 // login ***Ugly Hack***
 if($_POST['post_classroom']) {
	 if($login[$_POST['post_classroom']]) {
		 $_SESSION['authenticated']=$login[$_POST['post_classroom']];
		 
		 Header('Location: '.$etomite->rewriteUrls('[~'.$_POST['post_classroom'].'~]'));
		 exit;
	 } else {
		 sleep(2);
		 return "<p>Sorry, that Classroom is unavailable or does not exist.
 
 Click <a href='[~$loginpage~]'>HERE</a> to go back.</p>";
	 }
 }
 
 
 
 // if logged in
 
 if($_SESSION['authenticated']) {
	 session_destroy();
	 Header('Location: '.$etomite->rewriteUrls('[~'.$loginpage.'~]'));
	 exit;
 
 // login form
 } else {
	 return $passwordform;
	   
 }


#2 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 03 January 2008 - 02:26 AM

You already have a session instantiated when a page is requested so there is no real need to start a new session... A quick study of the authentication snippets, authenticate_visitor and Login|Logout, should help in getting headed in the right direction...

#3 Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts
  • Gender:Male

Posted 03 January 2008 - 03:11 AM

To get the "50" parameter from "$text=name1|50" you could use a few different PHP functions: substr($text,-2,2), explode('|',$text), strstr($text,'name1|', FALSE) depending on how you want to use it and what you want to return.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users