Jump to content

Show content to


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?

Link to comment
https://forums.phpfreaks.com/topic/287740-show-content-to/
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?

Link to comment
https://forums.phpfreaks.com/topic/287740-show-content-to/#findComment-1475979
Share on other sites

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
https://forums.phpfreaks.com/topic/287740-show-content-to/#findComment-1475986
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.