Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening a popup window only if a condition is met

Status
Not open for further replies.

camcim

Programmer
Jan 25, 2003
20
0
0
US
Hi all,
Can anyone tell me of a way to complete this process?

I currently have a page called genre.php
On this page i have a link that opens a javascript popup window called member_rating.php (this page has a session_start() associated with it so that only members can rate topics).
If the user is not a member, or for that matter, not logged in, the user is redirected to a page called login.php
Eg:
Code:
header("Location: login.php?id=member_rating&movie_id=$movie_id");
This all works fine except that the login.php page loads into the javascript popup window as well. I don't want it to load into this.
So how can i get the login.php page to load into the existing page (_self), and not the javascript popup window if they haven't logged in or are not a member?

Any ideas greatly appreciated.
camcim
 
Hi,

You dont say how you know if the user is logged in or not, so here is some psudo JavaScript code (give me more details if you need more specific code):

Code:
<a href=&quot;#&quot; onClick=&quot;navigate()&quot;>link</a>

function navigate(){
   if(loggedIn){
      window.open(&quot;member_rating.php&quot;);
   }else{
      window.location = &quot;login.php&quot;;
   }
}
Hope this helps. Shout if you need clarification.

Regards
Richard
 
Thanks for the reply Richard.

I'll try and clarify the situation.
I have a page called genre.php that will contain the
<a href=&quot;#&quot; onClick=&quot;navigate()&quot;>Rate</a>
The genre.php page is a visable page to all users.
This contains a list of different movies.
However, in order to rate a movie you have to be logged in and a php session is used to determine this.

I understand your javascript but can't work out how to check if a session already exists.
Part of your code says:
if(loggedIn){
How do a set a php session variable to be the loggedIn value?

I hope that makes more sense.

Cheers,
camcim
 
Guessing here...

but when you're generating the javascript have something like this...

<?
/* evaluate $logged_in to oh I dunno, true/false */
$logged_in = $_SESSION[&quot;however you're doing this&quot;];
..
..
..
echo &quot;
if ('$logged_in' == 'true') {
...
} else {
...
}
..
..
..
?>

That way the source of your page will simply look like
if ('true' == 'true') or
if ('' == 'true') or
if ('false' == 'true')

depending on how exactly you handle your sessions.

-Rob
 
Hi,

OK, so register a session variable with the logged is user's name, for example:
Code:
<?php
   $user = &quot;john&quot;; // from $_POST probably
   session_register(user);
?>

Then in your HTML code:
Code:
<input id=&quot;user&quot; type=&quot;hidden&quot; value=&quot;<?php echo $user; ?>&quot;>
Then in your Javascript function:
Code:
function navigate(){
   var loggedIn = document.getElementById(&quot;user&quot;).value;
   if(loggedIn != &quot;&quot;){
      window.open(&quot;member_rating.php&quot;);
   }else{
      window.location = &quot;login.php&quot;;
   }
}
So, essentially you store the logged in user name in a session variable. You write that out to your HTML page in a hidden field. You test that field in JavaScript to see if you have a user name or not - if you have you let them rate the movie.

Is this clear enough?

Cheers
Richard

P.S. There are many more ways to skin this cat ;)
 
Thanks guys, that should get the ball rolling.

Cheers,
camcim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top