boardom Forum Index boardom
b2 message board
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[Hacks] - Login box

 
Post new topic   Reply to topic    boardom Forum Index -> Hacks
View previous topic :: View next topic  
Author Message
dtdgoomba



Joined: 05 Aug 2002
Posts: 179
Location: Cambridge, MA

PostPosted: Wed Mar 19, 2003 6:39 pm    Post subject: [Hacks] - Login box Reply with quote

I promised this in another thread http://tidakada.com/board/viewtopic.php?t=2302 .
Added to b2-include/b2template.functions.php (I put mine at the end):
Code:

function loginBox(){
global $siteurl;
$logincookie = $_COOKIE['cafeloguser'];

if(!isset($_COOKIE['cafeloguser']) || $_COOKIE['cafeloguser'] == '') {
print("
<form name=\"\" action=\"".$siteurl."/b2login.php\" method=\"post\">
<input type=\"hidden\" name=\"redirect_to\" value=\"".$siteurl."/b2edit.php\" />
<input type=\"hidden\" name=\"action\" value=\"login\" />

  <table width=\"100\">
    <tr>
      <td align=\"right\">login</td>
      <td><input type=\"text\" name=\"log\" value=\"\" size=\"8\" />    </td>
    </tr>
    <tr>
      <td align=\"right\">password</td>
      <td><input type=\"password\" name=\"pwd\" value=\"\" size=\"8\" />    </td>
    </tr>
    <tr>
      <td> </td>
      <td><input type=\"submit\" name=\"Submit\" value=\"Log me in!\" class=\"search\">    </td>
    </tr>
    <tr>
      <td colspan=\"2\"><a href=\"".$siteurl."/b2register.php\"><br />
        New here?<br />
        Register for free!</a></td>
    </tr>
  </table>
</form>
");
}
else {
print("
<table width=\"100%\" cellspacing=\"2\"><tr><td>
Login:
</td></tr><tr><td>
<a href=\"".$siteurl."/b2edit.php\">".$logincookie."  is logged in, click here to post!</a>
<br /><br />
<a href=\"".$siteurl."/b2login.php\">Click here if you are not ".$logincookie." </a>
</td></tr></table>
<br /><br />
");
}
}


I didn't put any styles but I did use tables. Macshack mentioned he wasn't a fan of putting html into code, but this is pretty easy to alter, you can change the table to divs, put your own classes in, etc.

and finally to call this box, just make sure that blog.header.php is included at the top of your page and just put this code:
Code:

<?php loginBox(); ?>

where you want your box to show up.
-------------------------------------------
The only problem I had with the cookies was that the b2login.php was saving the cookie to point to my b2 subdirectory where it was located, so this box wouldn't work on the main page outside of that subdirectory. I had to change the setcookie in b2login to use the root of my site.

This may/may not need to be done for most b2users, so only refer to this if you're having issues discussed this thread:
http://tidakada.com/board/viewtopic.php?t=2302

In the b2login.php, I changed :

Code:

      setcookie("cafeloguser",$user_login,time()+31536000);
      if ($pass_is_md5) {
         setcookie("cafelogpass",$user_pass,time()+31536000);
      } else {
         setcookie("cafelogpass",md5($user_pass),time()+31536000);
      }

to
Code:

      setcookie("cafeloguser",$user_login,time()+31536000,"/",".mydomain.com");
      if ($pass_is_md5) {
         setcookie("cafelogpass",$user_pass,time()+31536000,"/",".mydomain.com");
      } else {
         setcookie("cafelogpass",md5($user_pass),time()+31536000,"/",".mydomain.com");
      }


and
Code:

case "logout":

   setcookie("cafeloguser");
   setcookie("cafelogpass");


changed to this:
Code:

case "logout":

   setcookie("cafeloguser","",time(),"/",".mydomain.com");
   setcookie("cafelogpass","",time(),"/",".mydomain.com");


That's all I did to get it to work on my site: http://www.goombalooza.com
If anyone wants to test it out and let me know how it goes, I'll be glad to help. Anyone else want to improve upon it or point out something, please do. Like Michael P said to my before, that's what forums are for!
_________________
Goombalooza! | Last X posts from Y Category | Login Box


Last edited by dtdgoomba on Wed Mar 19, 2003 6:44 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
dtdgoomba



Joined: 05 Aug 2002
Posts: 179
Location: Cambridge, MA

PostPosted: Wed Mar 19, 2003 6:43 pm    Post subject: Reply with quote

I forgot to mention what you'll actually see if you didn't look through the code right away:

login (box)
password (box)

New here?
Register for free! (which links to b2register.php)


if the person is already logged in from the cookie, you'd get

Login:
username is logged in, click here to post! (goes to b2edit.php)

Click here if you are not username (goes to b2login.php)
_________________
Goombalooza! | Last X posts from Y Category | Login Box
Back to top
View user's profile Send private message Visit poster's website
lepus



Joined: 13 Jun 2003
Posts: 15

PostPosted: Fri Jun 13, 2003 9:38 am    Post subject: Getting some errors. Reply with quote

where in the file should this go ?

Code:
function loginBox(){
global $siteurl;
$logincookie = $_COOKIE['cafeloguser'];

if(!isset($_COOKIE['cafeloguser']) || $_COOKIE['cafeloguser'] == '') {
print("
<form name=\"\" action=\"".$siteurl."/b2login.php\" method=\"post\">
<input type=\"hidden\" name=\"redirect_to\" value=\"".$siteurl."/b2edit.php\" />
<input type=\"hidden\" name=\"action\" value=\"login\" />

  <table width=\"100\">
    <tr>
      <td align=\"right\">login</td>
      <td><input type=\"text\" name=\"log\" value=\"\" size=\"8\" />    </td>
    </tr>
    <tr>
      <td align=\"right\">password</td>
      <td><input type=\"password\" name=\"pwd\" value=\"\" size=\"8\" />    </td>
    </tr>
    <tr>
      <td> </td>
      <td><input type=\"submit\" name=\"Submit\" value=\"Log me in!\" class=\"search\">    </td>
    </tr>
    <tr>
      <td colspan=\"2\"><a href=\"".$siteurl."/b2register.php\"><br />
        New here?<br />
        Register for free!</a></td>
    </tr>
  </table>
</form>
");
}
else {
print("
<table width=\"100%\" cellspacing=\"2\"><tr><td>
Login:
</td></tr><tr><td>
<a href=\"".$siteurl."/b2edit.php\">".$logincookie."  is logged in, click here to post!</a>
<br /><br />
<a href=\"".$siteurl."/b2login.php\">Click here if you are not ".$logincookie." </a>
</td></tr></table>
<br /><br />
");
}
}


Couse i tried to put it at the end but i just got a tone of error messages.

but mabye that could come from the header.php file. i dont know if its used. how do i know that ?
Back to top
View user's profile Send private message Visit poster's website
lepus



Joined: 13 Jun 2003
Posts: 15

PostPosted: Fri Jun 13, 2003 7:24 pm    Post subject: Reply with quote

Quote:
just make sure that blog.header.php is included at the top of your page


How do i know ?
Back to top
View user's profile Send private message Visit poster's website
dtdgoomba



Joined: 05 Aug 2002
Posts: 179
Location: Cambridge, MA

PostPosted: Fri Jun 13, 2003 9:40 pm    Post subject: Reply with quote

Strange, well, my function goes in that b2template.functions.php (wherever your b2-include directory is) after:
Code:


function is_new_day() {
        global $day, $previousday;
        if ($day != $previousday) {
                return(1);
        } else {
                return(0);
        }
}

and just before
Code:

?>


and then in your page where you want to call the login box, you need to put that php call to blog.header.php. If you look in your b2 index file that has your posts on it, you'll notice in your code that there is a call to blog.header.php
Code:

<?php /* Don't remove this line, it calls the b2 function files ! */ $blog=1; include ("b2/blog.header.php");


Whereever you call the login box, that page has to have that at the top since it calls all the b2 functions....

Does that help explain?

if you're getting errors, you can post them here and either I or someone else on this board will try to help you out. Smile
_________________
Goombalooza! | Last X posts from Y Category | Login Box
Back to top
View user's profile Send private message Visit poster's website
lepus



Joined: 13 Jun 2003
Posts: 15

PostPosted: Sat Jun 14, 2003 12:16 am    Post subject: Reply with quote

Quote:
Strange, well, my function goes in that b2template.functions.php (wherever your b2-include directory is) after:

Code:
function is_new_day() {
        global $day, $previousday;
        if ($day != $previousday) {
                return(1);
        } else {
                return(0);
        }
}

Quote:
and just before

Code:
?>


not to be a pain in the ass but i got

Code:
function apply_filters($tag, $string) {
   global $b2_filter;
   if (isset($b2_filter['all'])) {
      $b2_filter['all'] = (is_string($b2_filter['all'])) ? array($b2_filter['all']) : $b2_filter['all'];
      $b2_filter[$tag] = array_merge($b2_filter['all'], $b2_filter[$tag]);
      $b2_filter[$tag] = array_unique($b2_filter[$tag]);
   }
   if (isset($b2_filter[$tag])) {
      $b2_filter[$tags] = (is_string($b2_filter[$tag])) ? array($b2_filter[$tag]) : $b2_filter[$tag];
      $functions = $b2_filter[$tag];
      foreach($functions as $function) {
         $string = $function($string);
      }
   }
   return $string;
}

function add_filter($tag, $function_to_add) {
   global $b2_filter;
   if (isset($b2_filter[$tag])) {
      $functions = $b2_filter[$tag];
      if (is_array($functions)) {
         foreach($functions as $function) {
            $new_functions[] = $function;
         }
      } elseif (is_string($functions)) {
         $new_functions[] = $functions;
      }
/* this is commented out because it just makes PHP die silently
   for no apparent reason
      if (is_array($function_to_add)) {
         foreach($function_to_add as $function) {
            if (!in_array($function, $b2_filter[$tag])) {
               $new_functions[] = $function;
            }
         }
      } else */if (is_string($function_to_add)) {
         if (!@in_array($function_to_add, $b2_filter[$tag])) {
            $new_functions[] = $function_to_add;
         }
      }
      $b2_filter[$tag] = $new_functions;
   } else {
      $b2_filter[$tag] = array($function_to_add);
   }
   return true;
}



before the ?>

Dont know if that has something to do with it. ?
Back to top
View user's profile Send private message Visit poster's website
lepus



Joined: 13 Jun 2003
Posts: 15

PostPosted: Sat Jun 14, 2003 12:20 am    Post subject: heh Reply with quote

Well i got it almost working now. Very Happy

http://members.lycos.co.uk/aovikings2003/index.php

thanks for explaining it to me.
Back to top
View user's profile Send private message Visit poster's website
imatreeandurnot



Joined: 26 Sep 2002
Posts: 21

PostPosted: Sun Feb 22, 2004 8:23 pm    Post subject: Reply with quote

Hahaha, I doubt the person who wrote this still visits these forums, but, its worth the try.

Everything worked out ok! Except for when someone logs in, the "bla bla is logged in, click here to post" text doesnt show up for some reason. No biggie.
Back to top
View user's profile Send private message
dtdgoomba



Joined: 05 Aug 2002
Posts: 179
Location: Cambridge, MA

PostPosted: Sun Mar 14, 2004 7:02 am    Post subject: Been a loooong time Reply with quote

Well, it's obvious I haven't visited this thread in a while. Once I heard that b2 was splitting off and I found other projects to play with, I kinda disappeared from here. I did just realize I get hits to my site from this thread though.

I can't promise that I'll get back to people here with any help, but you're welcome to send me a private message since I think it'll then email me that someone is trying to reach me, and I'll see if I can dig through the code.

I haven't updated goombalooza in a while, but the code from here still seems to work on the site (amazingly enough...)
_________________
Goombalooza! | Last X posts from Y Category | Login Box
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    boardom Forum Index -> Hacks All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2 © 2001, 2002 phpBB Group