check if user is logged in with smf..

Started by Patey, April 18, 2014, 06:53:13 PM

Previous topic - Next topic

Patey

I want to have content on my website that will only be displayed if a user is logged in with smf, is that possible? if so could anyone point me in the right direction?

thanks in advance for any help!

EDIT-

I used this on my menu, which is located seperately in menu.php and included on other pages with a php include, to detect if the user is logged in. if they are, show logout, if they aren't show login. it works everywhere except on the forum itself. while on the forums it doesn't detect the user as logged in and shows the login button while the user is actually logged in.

<?php
if ($context['user']['is_logged']){
?>

<li><a href="/login/logout.php">Logout</a></li>
<?php }else{
?>

<li><a href="#modal-text" class="call-modal">Login</a></li>
<?php ?>


this is the entire menu code:
<link rel="stylesheet" href="/assets/css/modal.css">
<script src="/assets/js/modal.js"></script>
<link rel="stylesheet" href="/assets/css/menu.css">
<?php 
$current 
dirname($_SERVER['PHP_SELF']);
if (
$current = ! "/forums") {
}else{
require(
$_SERVER['DOCUMENT_ROOT']."/forums/api_smf.php");
require(
$_SERVER['DOCUMENT_ROOT']."/forums/SSI.php");
}
?>


<center>
<nav>
<ul>
<li><a href="/index.php">Home</a></li>
<li><a href="#">Modpack</a>
<ul>
<li><a href="/modpack/download.php">Download</a></li>
<li><a href="/modpack/list.php">Mod List</a></li>
<li><a href="/wiki/index.php">Wiki</a></li>
</ul>
</li>
<li><a href="#">Community</a>
<ul>
<li><a href="/forums/index.php">Forum</a></li>
<li><a href="/chat/index.php">Chat Room</a></li>
</ul>
</li>
<?php
if ($context['user']['is_logged']){
?>

<li><a href="/login/logout.php">Logout</a></li>
<?php }
if (!$context['user']['is_logged']){
?>

<li><a href="#modal-text" class="call-modal">Login</a></li>
<?php ?>
</ul>
</nav>
</center>

<section class="semantic-content" id="modal-text" tabindex="-1"
        role="dialog" aria-labelledby="modal-label" aria-hidden="true">

    <div class="modal-inner">
        <header id="modal-label">Login</header>
        <div class="modal-content">
<form action="/login/login_process.php" method="POST">

<table class="cnr">
<tr>
  <td>
   <input type="text" name="un" placeholder="Username or Email">
  </td>
</tr>
<tr>
  <td>
   <input type="password" name="pw" placeholder="Password">
  </td>
</tr>
<tr>
  <td>
   <font size="1">Stay logged in?</font><input type="checkbox" name="check" value="yes">
   <input type="hidden" name="location" value="<?php echo $_SERVER['PHP_SELF']; ?>">
   <input type="submit" name="submit" value="Login">
  </td>
</tr>
</table>


</form>
</div>
    </div>

    <a href="#!" class="modal-close" title="Close" data-close="Close"
        data-dismiss="modal">×</a>
</section>



To get the menu on the forum I included it with a php include on the theme's index.template, at the start of the template_html_above function like this:
function template_html_above()
{
include ($_SERVER['DOCUMENT_ROOT'].'/menu/menu.php');

Colin

"If everybody is thinking alike, then somebody is not thinking." - Gen. George S. Patton Jr.

Colin

Patey

#2
Thanks so much :)

was looking through the api thinking it would be in there.

Patey

Sorry to double post, but I still need a little help with this :(

anyone know what I've done wrong? I'm thinking it might be to do with including the menu in the template index, but I'm not sure how else to include the menu on the same page to even test it.

Kindred

Please be more specific...  what have you fone that is "not working"
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Patey

Quote from: Kindred on April 28, 2014, 10:12:08 PM
Please be more specific...  what have you fone that is "not working"

In my OP where I added the edit-
when on the actual forums the code I included on the index template for my menu doesn't detect the user as logged in.

Kindred

- is your "menu script" a separate php file?
- how do you "include the menu script on every page"?
- If it is a separate file, are you globalizing $context before you call it?

if it's not included inside an existing forum file, are you also requiring SSI.php?
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Patey

Quote from: Kindred on April 29, 2014, 01:00:37 PM
- is your "menu script" a separate php file?
- how do you "include the menu script on every page"?
- If it is a separate file, are you globalizing $context before you call it?

if it's not included inside an existing forum file, are you also requiring SSI.php?

sorry, edited my OP with more info

Kindred

well, you have not globalized $context...   so how would the system be able to use the value?


also, AFAIK, you can't use both the API and SSI...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Patey

thanks, I feel a little stupid now  :-[ after replying I re-read your post and realized I hadn't globalized a lot of things throughout the website. so far mixing API and SSI has worked, but I have yet to fully test it. is there anywhere I can look into that further?

Advertisement: