Topic: Login Problem from external site

Hello. I have been browsing the forums and I haven't quite found the solution to my problem.  I have a login box on the main page of my site that logs a user into the forums. My problem is that after a user logs in, the page just refreshes and login box reappears. Is there a way I can have it say "Welcome Guest, Please login" if no one has logged in yet, and if a user is logged in it shows "Welcome [user]" and maybe under that have like a sub menu, like " Administration, Profile, Messages, Logout (if the user is an admin) or just "Profile, Messages, Logout" (if the user is not)

heres the current code im using

?php define('PUN_ROOT', 'boards/'); ?>
<?php
require PUN_ROOT.'include/common.php';
define('PUN_QUIET_VISIT', 1);
    $redirect_url = 'boards/index.php' ;
    if(isset($_SERVER['REQUEST_URI']))
        $redirect_url = $_SERVER['REQUEST_URI'] ;
 
    require PUN_ROOT.'lang/'.$pun_user['language'].'/login.php';

?>
          <form id="login" method="post" action="<?php echo PUN_ROOT.'login.php?action=in'; ?>">
            <input type="hidden" name="form_sent" value="1" />
            <input type="hidden" name="redirect_url" value="<?php echo $redirect_url ?>" />  
            <p align="center" style="margin-top: 2; margin-bottom: 2">
            <b><font face="Verdana" style="font-size: 9pt" color="#FFFFFF">
            Username:</font></b></p>
            <p align="center" style="margin-top: 2; margin-bottom: 2">
            <input type="text" name="req_username" size="13" style="font-family: Georgia; font-size: 8pt; font-weight: bold"></p>
            <p align="center" style="margin-top: 2; margin-bottom: 2"><b>
            <font face="Verdana" style="font-size: 9pt" color="#FFFFFF">
            Password:</font></b></p>
            <p align="center" style="margin-top: 2; margin-bottom: 2">
            <input type="password" name="req_password"  size="13" style="font-family: Georgia; font-size: 9pt; font-weight: bold"></p>
            <p align="center" style="margin-top: 0; margin-bottom: 0">
            <input type="image" src="img/login.gif" name="login" value="<?php echo $lang_common['Login'] ?>" />
          </form>

Re: Login Problem from external site

Use smth like that to determine who the user is.

//if user guest
if ($pun_user['is_guest'])
  code;
//if user is a administrator
else if ($pun_user['group_id] == 1)
  code;
//if user is not an admin
else
  code;

Re: Login Problem from external site

I'll give it a try, thanks!

4 (edited by STK_sedated29 2008-10-01 20:58)

Re: Login Problem from external site

okay I have another login iissue.....

I have integrated my forums with my site....

http://www.xalaris.net/boards/index.php

When I try to login on the login box I created, I get a white page that says "Unable to Connect to Database!!" but if I go back, im logged in. The same thing happends when I try to log out...

I have put the following login script in my /includes/user folder and I have it included on my main.tpl using <pun_include "login.php">

<?php
define('PUN_ROOT', '../');
define('PUN_QUIET_VISIT', 1);
if (!$pun_user['is_guest']) {
      echo '<p align="center" style="margin-top: 0; margin-bottom: 2"><font face="Verdana" style="font-size: 9pt" color="#FFFFFF">Hello '.pun_htmlspecialchars($pun_user['username']);
      
      $avatardir = "img/avatars";
            if ($img_size = @getimagesize($avatardir.'/'.$pun_user['id'].'.gif'))
                $user_avatar = '<img src="'.$avatardir.'/'.$pun_user['id'].'.gif" alt="" border="0"/>
<body topmargin="0" leftmargin="0">

';
            else if ($img_size = @getimagesize($avatardir.'/'.$pun_user['id'].'.jpg'))
                $user_avatar = '<img src="'.$avatardir.'/'.$pun_user['id'].'.jpg" alt="" border="0"/>';
            else if ($img_size = @getimagesize($avatardir.'/'.$pun_user['id'].'.png'))
                $user_avatar = '<img src="'.$avatardir.'/'.$pun_user['id'].'.png" alt="" border="0" />';
else
$user_avatar = '<img src="'.$avatardir.'/no-avatar.jpg" alt="" border="0" />';

echo "<br><br>$user_avatar<br><br><b><font face='Verdana' style='font-size: 9pt' color='white'><a href='boards/login.php?action=out&amp;id=".$pun_user['id']."&amp;csrf_token=".sha1($pun_user['id'].sha1(get_remote_address()))."'>".$lang_common['Logout']."</a><br><br>" ; }

else
{
    $redirect_url = '' ;
    if(isset($_SERVER['REQUEST_URI']))
        $redirect_url = $_SERVER['REQUEST_URI'] ;
 
    require PUN_ROOT.'lang/'.$pun_user['language'].'/login.php';
     echo '<center><p align="center" style="margin-top: -15; margin-bottom: 2"><font face="Verdana" style="font-size: 9pt" color="white"><br>Welcome Guest</font></center>';
?>
           <form id="login" method="post" action="<?php echo PUN_ROOT.'login.php?action=in'; ?>">
            <input type="hidden" name="form_sent" value="1" />
            <input type="hidden" name="redirect_url" value="<?php echo $redirect_url ?>" />  
            <p align="center" style="margin-top: 2; margin-bottom: 2">
            <b><font face="Verdana" style="font-size: 9pt" color="#FFFFFF">
            Username:</font></b></p>
            <p align="center" style="margin-top: 2; margin-bottom: 2">
            <input type="text" name="req_username" size="13" style="font-family: Georgia; font-size: 8pt; font-weight: bold"></p>
            <p align="center" style="margin-top: 2; margin-bottom: 2"><b>
            <font face="Verdana" style="font-size: 9pt" color="#FFFFFF">
            Password:</font></b></p>
            <p align="center" style="margin-top: 2; margin-bottom: 2">
            <input type="password" name="req_password"  size="13" style="font-family: Georgia; font-size: 9pt; font-weight: bold"></p>
            <p align="center" style="margin-top: -5; margin-bottom: -15">
            <input type="image" src="imgs/login.gif" name="login" value="<?php echo $lang_common['Login'] ?>" width="80" height="34" /></form>
          <?php

}

Can anyone tell me what im doing wrong? sad

**EDIT**

The "Unable to Connect to Database!!" message appears when I try posting, but if go back to the index, the post is there


thanks,
Juston

Re: Login Problem from external site

I was able to fix it myself... there was something wrong with the redirect.tpl after I modified it, I just went back to using the default one

Re: Login Problem from external site

I thought I had it fixed, but still getting the data base errors sad(

Re: Login Problem from external site

Enable debug mode and paste the full error message.

Sorry. Unactive due to personal life.

Re: Login Problem from external site

Sorry I didnt see your message in time.... turns out I had another script that wasnt making a database connection, it was no fault of punbb... smile

Re: Login Problem from external site

Slavok wrote:

Use smth like that to determine who the user is.

//if user guest
if ($pun_user['is_guest'])
  code;
//if user is a administrator
else if ($pun_user['group_id] == 1)
  code;
//if user is not an admin
else
  code;

Okay I have been trying to get the above working right, but I am having nothing but problems. Someone please tell me what im doing wrong.... heres my code....

<?php
//define('PUN_ROOT', './boards/');
//require PUN_ROOT.'include/common.php';
//define('PUN_QUIET_VISIT', 1);

if (!$pun_user['is_guest']) {
      echo '<p align="center" style="margin-top: 0; margin-bottom: 2"><font face="Verdana" style="font-size: 9pt" color="#FFFFFF">Hello '.pun_htmlspecialchars($pun_user['username']);
      
      $avatardir = "boards/img/avatars";
            if ($img_size = @getimagesize($avatardir.'/'.$pun_user['id'].'.gif'))
                $user_avatar = '<img src="'.$avatardir.'/'.$pun_user['id'].'.gif" alt="" border="0"/>
<body topmargin="0" leftmargin="0">

';
            else if ($img_size = @getimagesize($avatardir.'/'.$pun_user['id'].'.jpg'))
                $user_avatar = '<img src="'.$avatardir.'/'.$pun_user['id'].'.jpg" alt="" border="0"/>';
            else if ($img_size = @getimagesize($avatardir.'/'.$pun_user['id'].'.png'))
                $user_avatar = '<img src="'.$avatardir.'/'.$pun_user['id'].'.png" alt="" border="0" />';
else
$user_avatar = '<img src="'.$avatardir.'/no-avatar.jpg" alt="" border="0" /><br>';


echo "<br><br>$user_avatar<br><br>";
//if user is a admin
if ($pun_user['g_id'] == 1)
echo "";
echo "Forum Admin<br>";
echo "Poll Admin<br>";
echo "Webmail<br>";
//For All Members
else if ($pun_user['group_id'] == 4)
echo "Your Profile<br>";
echo "Message Box<br><br>";
echo "<b><font face='Verdana' style='font-size: 9pt' color='white'><a  style='text-decoration: none' href='boards/login.php?action=out&amp;id=".$pun_user['id']."&amp;csrf_token=".sha1($pun_user['id'].sha1(get_remote_address()))."'>".$lang_common['Logout']."</a><br><br>" ; }
else
{
    $redirect_url = '' ;
    if(isset($_SERVER['REQUEST_URI']))
        $redirect_url = $_SERVER['REQUEST_URI'] ;
 
    require PUN_ROOT.'lang/'.$pun_user['language'].'/login.php';
     echo '<center><p align="center" style="margin-top: -15; margin-bottom: 2"><font face="Verdana" style="font-size: 9pt" color="white"><br>Welcome Guest</font></center>';
?>

And this is the error I keep getting...

PHP Parse error:  syntax error, unexpected T_ELSE in /var/www/web3/web/login.php on line 31

I have no clue what im doing wrong but any help would be great! smile

thanks
Juston

Re: Login Problem from external site

Looks like you forget the { ... } here:

if ($pun_user['g_id'] == 1)
echo "";
echo "Forum Admin<br>";
echo "Poll Admin<br>";
echo "Webmail<br>";
//For All Members
else if ($pun_user['group_id'] == 4)
echo "Your Profile<br>";
echo "Message Box<br><br>";
echo "<b><font face='Verdana' style='font-size: 9pt' color='white'><a  style='text-decoration: none' href='boards/login.php?action=out&amp;id=".$pun_user['id']."&amp;csrf_token=".sha1($pun_user['id'].sha1(get_remote_address()))."'>".$lang_common['Logout']."</a><br><br>" ; }
else

Should be kind of:

if ($pun_user['g_id'] == 1)
{
echo "";
echo "Forum Admin<br>";
echo "Poll Admin<br>";
echo "Webmail<br>";
//For All Members
}
else if ($pun_user['group_id'] == 4)
{
echo "Your Profile<br>";
echo "Message Box<br><br>";
echo "<b><font face='Verdana' style='font-size: 9pt' color='white'><a  style='text-decoration: none' href='boards/login.php?action=out&amp;id=".$pun_user['id']."&amp;csrf_token=".sha1($pun_user['id'].sha1(get_remote_address()))."'>".$lang_common['Logout']."</a><br><br>" ;
}
else

Anyway, do not use us as PHP-parsers please. The line number is specified in your error message. Take a look at it or post just this line (and +-2 lines around) if you can't fogure out the error and need help.

Good luck.

Carpe diem