Zubrag.com
September 09, 2010, 10:57:41 pm *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: require logged in  (Read 1062 times)
pearible
Newbie
*
Posts: 1


« on: July 20, 2009, 01:52:01 pm »

Hello all - I'm trying to require that users be logged in in order for the links to work - I've seen some examples here already, and have some pages on my site already logged-in/protected, but I can't seem to get this to work.

When adding the appropriate code, it re-directs me to log in... even if I *AM* logged in. There's simply no circumstance where it lets me proceed.

Here's what I'm using on other pages...

Code:
<?php

$reqAgcID 
$_REQUEST['reqAgcID'];
if(!isset(
$_SESSION['memberid']) || ($_SESSION['memberid'] == ''))
   {
     
header("Location:login.php?msg=logfirst");
 exit;
   }

And tried using on download.php

Any help?

Logged
mtg
Newbie
*
Posts: 15


« Reply #1 on: July 20, 2009, 02:41:18 pm »

How/where is the $_SESSION['memberid'] var being created? I'd say the session is not being created or has no value. What outputs when you try to echo the value of $_SESSION['memberid'] on the download.php page? IE just do something like this at the top of download.php

Code:
<?php echo "value of memberid= ".$_SESSION['memberid']; exit(); ?>

If it doesn't output a value, then there's your problem. To share your sessions between pages, session_start(); is required before referencing your session variables and resuming the current session.

Try changing your code to this:

Code:
<?php

session_start
();
$reqAgcID $_REQUEST['reqAgcID'];
if(!isset(
$_SESSION['memberid']) || ($_SESSION['memberid'] == ''))
   {
     
header("Location:login.php?msg=logfirst");
 exit;
   }

Note: I left the PHP tag open like in your example.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC