Jump to content

Making a modal window popup if not confirmed member


phpchick

Recommended Posts

I created a wordpress webpage that I want to protect with a login window. If the user does not have a authenticated session, I want a modal window to popup that asks them to either register or signup. I'm using the fancybox script to do this.

 

The way the modal window works is it is embedded in the <body> tag.

 

To make the modal window popup you basically use this body tag,

<body onload='$("a#various3").trigger("click");' > website html code </body>

 

At the very beginning of the page I want protected, I have the following code, it checks to see if the user has logged in already and gained an authenticated session.

 

<?php

require_once 'Membership.php';
$membership = New Membership();

$membership->confirm_Member();

?>

 

 

and this is what Membership.php looks like

<?php

require 'Mysql.php';

class Membership {

function validate_user($email, $password) {
	$mysql = New Mysql();
	$ensure_credentials = $mysql->verify_Username_and_Pass($email, $password);
	// if matched pass then authorize the session
	if($ensure_credentials) {
		$_SESSION['status'] = 'authorized';
		header("location: index.php"); //this is the location to where we send the user if they authenticate
	} else return "Please enter a correct username and password";

} 

function log_User_Out() {
	if(isset($_SESSION['status'])) {
		unset($_SESSION['status']);

		if(isset($_COOKIE[session_name()])) 
			setcookie(session_name(), '', time() - 1000);
			session_destroy();
	}
}

function confirm_Member() {
	session_start();
	if( $_SESSION['status'] !='authorized')   {
		$makemodal = 1;
	header("location: /member");

	}
	// If they are not authorized to view this page, send them here, here we would want to boot up the modal
}

}

 

So, what I think I'm doing here towards the end is, If they are NOT authenticated, make the string $makemodal = 1 and then send them to the protected website. This section here

	if( $_SESSION['status'] !='authorized')   {
		$makemodal = 1;
	header("location: /member");

 

And then, on the page in question, I did this to the <body> tag. (because if you remember the the body tag is what makes the modal window popup).

 

I modified the body tag to do this.

 

<body <?php if ($makemodal = 1) echo  "onload='$(\"a#various3\").trigger(\"click\");'  "; ?>>

 

In Membership.php I made $makemodal = 1 if the user was unauthenticated. So I thought I could echo in the requirements of popping up the window upon  upon $makemodal =1.

 

I am getting this error message

 

This webpage has a redirect loop

The webpage at http://site.com/member has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer.

Here are some suggestions:

Link to comment
Share on other sites

In Membership.php I took out this line of code

 

header("location: /member");

 

 

and it stopped the endless redirect loop.

 

However I am not getting the behaviour I want.

 

on the protected page

 

if I do

 

<body <?php body_class(); ?> <?php if ($makemodal = 1) echo  "onload='$(\"a#various3\").trigger(\"click\");'  "; ?> > 

 

the modal window will pop up. however, if I change the value of $makemodal in Membership.php to something other than 1, the modal window still shows up, which means something is not right.

 

  :(

Link to comment
Share on other sites

could the problem be that      $makemodal = 1      in Membership.php is not carrying over to the other page?

 

 

on the protected page i have

 

<?php

require_once 'Membership.php';
$membership = New Membership();

$membership->confirm_Member();

?>

Link to comment
Share on other sites

I think I got it to work....

 

I changed $makemodal to

 

$_SESSION['$makemodal']

 

 

in both files because apparently this is the only way the variable will transfer over I believe.

 

But I hope it will not screw up the "session" of the authentication, like logging in, logging out. etc

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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