How to restrict access to PHP pages?

Started by CFCParadox, May 25, 2010, 08:44:50 PM

Previous topic - Next topic

CFCParadox

How can I restrict access to PHP pages using SSI functions? I want to block people from a page unless they are logged in.

Thanks,
Paradox
characters remaining: 575

Kays

With SSI.php included.


if ($context['user']['is_logged'])
{
    // Stuff members can see
}
else
{
   // You are a guest so go away
}

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

CFCParadox

characters remaining: 575

JBlaze

if ($user_info['is_guest'])
    die('Go away...');
Jason Clemons
Former Team Member 2009 - 2012


JBlaze

Quote from: flapjack on May 28, 2010, 09:10:09 PM
Quote from: CFCParadox on May 28, 2010, 08:59:07 PM
That doesn't seem to work.
did you register a global variable?

Don't need to unless it's being called inside a function that hasn't already included SSI.php.
Jason Clemons
Former Team Member 2009 - 2012

CFCParadox

Thanks JBlaze but that isn't working too. I included the SSI.PHP at the top <?php require("/home/combatc1/public_html/forums/SSI.php"); ?> and inserted the code you gave me.

Is there anything I am missing?
characters remaining: 575

JBlaze

Quote from: CFCParadox on May 28, 2010, 10:04:27 PM
Thanks JBlaze but that isn't working too. I included the SSI.PHP at the top <?php require("/home/combatc1/public_html/forums/SSI.php"); ?> and inserted the code you gave me.

Is there anything I am missing?

Paste the entire code you are using.
Jason Clemons
Former Team Member 2009 - 2012

CFCParadox

Wow I feel so stupid now :P

Here it is:


<?php
                         
if ($context['user']['is_guest'])
 die('Go away...');
                         
?>

characters remaining: 575

CFCParadox

Okay so how would I display this:


<h3>Combat FPS Signature generators</h3>
<p>Combat FPS offers some of the best tools to display your pride in-game or on the forums! We currently have 3 signature generators for Combat Arms, A.V.A and our Forum but more is to come soon. In order to receive access to the signature generators please login or register to continue.</p>
<p>*Notice: CFC Signature Generator 2.0 is currrently in development and will include new features, customization and new backgrounds!       </p>
  <p><a href="http://combatfps.com/casiggen/">Combat Arms Signature Generator:</a></p>
<p><a href="http://combatfps.com/casiggen/"><img src="http://combatfps.com/casiggen/createimg.php?player=Emnesty&amp;signature=CFC1" alt="" width="400" height="100" /></a></p>
    <p><a href="http://combatfps.com/avasiggen/">A.V.A Signature Generator:</a></p>
                            <p><a href="http://combatfps.com/avasiggen/"><img src="http://combatfps.com/avasiggen/createimg.php?player=ShamanRoy&amp;signature=CFC27" alt="" width="400" height="100" /></a></p>
<p><a href="http://combatfps.com/forumsiggen/">Forums Signature Generator:</a></p>
<p><a href="http://combatfps.com/forumsiggen/"><img src="http://combatfps.com/forumsiggen/createimg.php?player=Paradox" alt="" width="400" height="100" /></a></p>
<p>&nbsp;</p>


To guests only?
characters remaining: 575

TehCraw


<?php
require_once('/home/combatc1/public_html/forums/SSI.php');

if (
$context['user']['is_guest'])
{
echo 
'
<h3>Combat FPS Signature generators</h3>
                     <p>Combat FPS offers some of the best tools to display your pride in-game or on the forums! We currently have 3 signature generators for Combat Arms, A.V.A and our Forum but more is to come soon. In order to receive access to the signature generators please login or register to continue.</p>
                     <p>*Notice: CFC Signature Generator 2.0 is currrently in development and will include new features, customization and new backgrounds!                  </p>
                    <p><a href="http://combatfps.com/casiggen/">Combat Arms Signature Generator:</a></p>
                     <p><a href="http://combatfps.com/casiggen/"><img src="http://combatfps.com/casiggen/createimg.php?player=Emnesty&amp;signature=CFC1" alt="" width="400" height="100" /></a></p>
                   <p><a href="http://combatfps.com/avasiggen/">A.V.A Signature Generator:</a></p>
                            <p><a href="http://combatfps.com/avasiggen/"><img src="http://combatfps.com/avasiggen/createimg.php?player=ShamanRoy&amp;signature=CFC27" alt="" width="400" height="100" /></a></p>
<p><a href="http://combatfps.com/forumsiggen/">Forums Signature Generator:</a></p>
                     <p><a href="http://combatfps.com/forumsiggen/"><img src="http://combatfps.com/forumsiggen/createimg.php?player=Paradox" alt="" width="400" height="100" /></a></p>
                     <p>&nbsp;</p>

'
;
}

?>

Any fool can write code that a computer can understand. Good programmers write code that humans can understand. - Martin Fowler

CFCParadox

characters remaining: 575

JBlaze

Jason Clemons
Former Team Member 2009 - 2012

smp420

"Things turn out best for those who make the best of the way things turn out." -Jack Buck

CFCParadox

I don't want to show the login text but the actual boxes and form that you fill out to login which comes from here:

<script type="text/javascript" src="http://combatfps.com/forums/Themes/default/scripts/sha1.js"></script>

<form action="http://forums.combatfps.com/index.php?action=login2" name="frmLogin" id="frmLogin" method="post" accept-charset="UTF-8"  onsubmit="hashLoginPassword(this, '24014c4e06c9ab0dd67f77dbfe1cf1dc');">
<div class="tborder login">

<div class="cat_bar">
<h3 class="catbg">
<span class="ie6_header floatleft"><img src="http://combatfps.com/forums/Themes/combatfpsmania/images/icons/login_sm.gif" alt="" class="icon" /> Login</span>
</h3>
</div>
<span class="upperframe"><span></span></span>
<div class="roundframe">
<dl>

<dt>Username:</dt>
<dd><input type="text" name="user" size="20" value="" class="input_text" /></dd>
<dt>Password:</dt>
<dd><input type="password" name="passwrd" value="" size="20" class="input_password" /></dd>
</dl>
<dl>
<dt>Minutes to stay logged in:</dt>

<dd><input type="text" name="cookielength" size="4" maxlength="4" value="9999" class="input_text" /></dd>
<dt>Always stay logged in:</dt>
<dd><input type="checkbox" name="cookieneverexp" class="input_check" onclick="this.form.cookielength.disabled = this.checked;" /></dd>
</dl>
<p><input type="submit" value="Login" class="button_submit" /></p>
<p class="smalltext"><a href="http://forums.combatfps.com/index.php?action=reminder">Forgot your password?</a></p>
<input type="hidden" name="hash_passwrd" value="" />
</div>

<span class="lowerframe"><span></span></span>
</div></form>
<script type="text/javascript"><!-- // --><![CDATA[
document.forms.frmLogin.user.focus();
// ]]></script>
characters remaining: 575

CFCParadox

characters remaining: 575

JBlaze

Open up SSI.php and look at the ssi_login() function.

That will show you how you need to add a login form.
Jason Clemons
Former Team Member 2009 - 2012

CFCParadox

I guess I'll have to use that then.

Do you also know how to display a register form on another page too?
characters remaining: 575

JBlaze

It's common sense. Take a look at how SMF does it, then just mimic that into wherever else you need.
Jason Clemons
Former Team Member 2009 - 2012

Advertisement: