Using Log in Registration, problem going between admin/site

Need some help with the script?

Using Log in Registration, problem going between admin/site

Postby eberswine » Thu Oct 23, 2008 5:13 am

I am using the Login box with registration.

I am have my users go to a log in box on the site ( not in the news )
** using the login box plugin

I also have this script to show that they are logged in when browsing the site:
Code: Select all
<div id="logged-in"><small style="font-size:15px">
<?PHP if($is_logged_in){

      echo $user_avatar[$member['username']];

} ?>
<?PHP if($is_logged_in){

echo 'Hello <b><a href="http://www.website.com/admin/index.php?mod=personal">'.($username ? $username : (cookie ? $_COOKIE['login_username'] : $_SESSION['login_username'])).'</a></b> | <a href="http://www.website.com/admin/logout.php?action=logout">Log out.</a>';

}

else{

echo '<a href="http://www.website.com/login.php">log in</a> | <a href="http://www.website.com/registration.php">register</a>';

} ?></small>
</div>


The problem is when or if they do log in from the /admin/ area *CNR news section* then they go back and browse the website, it isn't remembering them --- some sort of session and or cookie is lost from the CNR/admin/index.php log in page to the regular front end of the website....?
I was also having problems with the logout too.. If you see above, I have them logging out through the admin CNR page, that I pretty much just did a save as index.php page and changed some design aspects...
What code in the index.php do I need in these other pages to remember the session and going back and forth to the NEWS section and the regular website... >????
The code I include should recognize if I user is logged in through the website log in box -- which it does a great job at it, but going back and forth it isn't remembering the session....
need some help.
thanks dudes.
User avatar
eberswine
 
Posts: 289
Joined: Thu Apr 26, 2007 7:23 pm

Postby nam » Thu Oct 23, 2008 1:15 pm

For me it works fine, once a user is logged in any page, the login session is available throughout the CNR.

But I don't have the “admin” folder in my installation and the index.php (where user needs to login) file is in the same folder where my other php files are located, I mean in the main directory of CNR.
User avatar
nam
 
Posts: 221
Joined: Sat Dec 23, 2006 9:10 pm

Postby FI-DD » Fri Oct 24, 2008 3:20 pm

Check the cookie code in head.php. Do you have the slash at the end of the code?
@setcookie('lastusername', $username, time() + 1012324305, '/');


If yes, then the cookie should be available everywhere.
User avatar
FI-DD
Admin
 
Posts: 2971
Joined: Thu Sep 22, 2005 11:27 am
Location: Germany

Postby scottdallas » Tue Oct 28, 2008 12:27 am

I'm back to my old ways of pushing cnr to the limits.. and tonight it's tweaking the membership area. I looked at my code as well and did not see the trailing /

Should I add this? I've done it and I'm going to see what difference it makes in my site/code.
Everyday I'm tumblin http://scodal.tumblr.com
User avatar
scottdallas
 
Posts: 2209
Joined: Thu May 04, 2006 6:46 pm
Location: US

Postby eberswine » Tue Oct 28, 2008 4:36 am

Mine is added in head.php --- but it still doesn't make a difference.. maybe it has to deal with the loginbox.php file???
User avatar
eberswine
 
Posts: 289
Joined: Thu Apr 26, 2007 7:23 pm

Postby Ramon » Tue Oct 28, 2008 5:00 pm

Those external logins never worked out for me. So i just threw it all away and decided to just send the informatie to the index.php file of the CNR and add a condition which brings it back to the page where it was when i logged in using Javascript and some PHP $_SERVER superglobals.

Something like..
Code: Select all
<?php
  $url = $_SERVER['REQUEST_URI'].
?>


Code: Select all
<form method="post" action="path/to/cnr/index.php">
<input type="hidden" name="url" value="<?php echo $url; ?>" />
Username <input type="text" name="username"></input>
Password <input type="password" name="password"></input>
<input type="submit" value="login">
</form>


and then in cnr/index.php add something like ->

Code: Select all
<?php
  if(isset($url)){
  header("Location: ".$url);
}
?>


I'll work it out better when i'm at home again. I was going to rewrite it anyway to make it AJAX.
Image
Ramon
 
Posts: 599
Joined: Wed Oct 12, 2005 8:51 pm
Location: Hoogeveen, NL

Postby Triton » Wed Mar 11, 2009 7:22 am

I was having lots of trouble with the login box mod too.

This is what got it working for me. Whether I login at the admin panel or on the front page, I stay logged in until I logout from either one, then I am logged out from both.

Since there is already a login routine in head.php and a logout routine in index.php I decided to use those ... basically. I commented out the login routine and some other blocks in loginbox.php and replaced the logout routine as well. Then I changed act to action and login_username to username.

Here's what loginbox.php looks like for me now.

Code: Select all
<?php
if (!defined('CN_INIT_LOGINBOX')) {

   define('CN_INIT_LOGINBOX', true);

   $echo = cute_lang();
   if(session){
      session_start();
   }
   $username = $_POST['username'];
   $password = $_POST['password'];

   if($_GET['action'] == 'logout'){
         setcookie('md5_password', '', time() - 3600 * 24 * 365, '/');
         setcookie('username', '', time() - 3600 * 24 * 365, '/');
         setcookie('login_referer', '');
         @session_destroy();
         @session_unset();
         @setcookie(session_name(), '');
            $is_logged_in = false;
       header('Location: '.$PHP_SELF);
   }
}
else{

   if (!$is_logged_in){
   
   //The login box
   ?>
   <form method="post" action="<?=$PHP_SELF; ?>">
   <table>
      <tr>
         <td>Username:<br><input type="text" name="username" size="14"></td>
      </tr>
      <tr>
         <td>Password:<br><input type="password" name="password" size="14"></td>
      </tr>
      <tr>
         <td><input type="submit" value="OK"></td>
      </tr>
   </table>
        <input type="hidden" name="action" value="dologin">
</form>
   <?
   
   
   }
   else{
      echo 'Logged in as <b>'.($username ? $username : (cookie ? $_COOKIE['username'] : $_SESSION['username'])).'</b> <br /><a href="'.$PHP_SELF.'?action=logout">Log out</a>';
   }
   
   echo $error;

}
?>
Last edited by Triton on Thu Mar 12, 2009 1:10 am, edited 1 time in total.
Triton
 
Posts: 7
Joined: Tue Mar 10, 2009 2:00 pm

Postby nolikewise » Wed Mar 11, 2009 9:25 pm

I tried it, liter and better... thanks for it... But i have no idea why you use .ini and not .php, i copied the code you gave into loginbox.php and it made a bit difference for speed. Also this works in every part of CNR, when you log in, you are in whole CNR.
nolikewise
 
Posts: 177
Joined: Mon Dec 17, 2007 8:47 am
Location: Turkiye

Postby Triton » Thu Mar 12, 2009 1:13 am

Glad to hear that it works for other people too.

I don't know why I wrote .ini instead of .php. :!: :?: I've edited my post and fixed that.
Triton
 
Posts: 7
Joined: Tue Mar 10, 2009 2:00 pm


Return to Help



Who is online

Users browsing this forum: No registered users and 1 guest

cron