Jump to content

Show content to


ShaneW1992
Go to solution Solved by ShaneW1992,

Recommended Posts

Hi there,

 

I'm using Jmemeber77's user script (updated by another source for better security) over at http://gamer-cafe.net/ and I'm having a little trouble.

 

 

I would like to show the log in area to guests;

<form action="process.php" method="POST">
		<p class="Loginform">Username:<input type="text" name="user" maxlength="15" value="<?php echo $form->value("user"); ?>"><?php echo $form->error("user"); ?>
		&nbsp&nbsp&nbsp&nbsp&nbsp
		Password:<input type="password" name="pass" maxlength="15" value="<?php echo $form->value("pass"); ?>"><?php echo $form->error("pass"); ?>
		
			&nbsp&nbsp&nbsp
			<input type="hidden" name="sublogin" value="1">
			<input type="submit" value="Login" style="position: absolute; left: -9999px; width: 1px; height: 1px;">
			<input type="checkbox" name="remember" <?php if($form->value("remember") != ""){ echo "checked"; } ?>>
		<a href="forgotpass.php">Forgot Password?</a></p>
	</form>

then, once a users credentials are established and logged in, remove it and replace it with;

<?php
/**
 * User has already logged in, so display relavent links, including
 * a link to the admin center if the user is an administrator.
 */
if($session->logged_in){
   echo "<h1>Logged In</h1>";
   echo "Welcome <b>$session->username</b>, you are logged in. <br><br>"
       ."[<a href=\"userinfo.php?user=$session->username\">My Account</a>]   "
       ."[<a href=\"useredit.php\">Edit Account</a>]   ";
   if($session->isAdmin()){
      echo "[<a href=\"admin/index.php\">Admin Center</a>]   ";
   }
   echo "[<a href=\"process.php\">Logout</a>]";
}
else
?>

I know that's using echo, but I would like to use the system;

<?php if ($session->logged_in) ?>

/* Content for logged in users */

<?php else ?>

/* Content for guests */

Which I had set-up previously for my user management, but when I use it with this, it gives me an unexpected error (or it displays the site content twice). I have skimmed through Session.php (http://ideone.com/FkxVfH) but I'm not really sure what to use.

 

 

 

What am I doing wrong?

Edited by ShaneW1992
Link to comment
Share on other sites

 

 

I know that's using echo, but I would like to use the system;

Thats fine. Just remove echo's. When you come to a PHP variable you'll need to wrap it in php tags and echo it.

<?php if ($session->logged_in): ?>

    <h1>Logged In</h1>
    Welcome <b><?php echo $session->username; ?></b>, you are logged in. <br><br>
    [<a href="userinfo.php?user=<?php echo $session->username; ?>">My Account</a>]   
    [<a href="useredit.php">Edit Account</a>]   

  <?php if($session->isAdmin()): ?>
    [<a href="admin/index.php">Admin Center</a>]   
  <?php endif; ?>
    [<a href="process.php">Logout</a>]

<?php else: ?>

    /* content for guests */

<?php endif; ?>

 

 

it gives me an unexpected error

Helps if you post the error(s) in full here

 

 

 

I have skimmed through Session.php (http://ideone.com/FkxVfH) but I'm not really sure what to use.

What relevance does this have?

Edited by Ch0cu3r
Link to comment
Share on other sites

  • Solution

Thank you so much! I believe I was just missing the colon from each.

 

 

I thought session.php is where it gets the variables etc. Was worth mentioning, I didn't get the original script as it is old and not secure, so I wasn't sure if it was calling the wrong variable for the logged in users or not.

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.