Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 05-04-2006, 01:01 PM
Eagle Creek's Avatar
Eagle Creek Eagle Creek is offline
 
Join Date: Jan 2004
Location: Netherlands
Posts: 742
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Getting information out of my forums, to show it on an other page

Howdy!

I have a question :bunny:.

I run a 3.5.4 board and that's running fine. In co?peration with some people we are planning to set up a site. On that site we want to have some integration with the forums. What do we want:
  • You can log in from the site. The data from the forumsdatabase will be used.
  • You can register from the site. The data will be put into the forumsdatabase.
  • You can edit your forumprofileinfo from the site. So there you have a button called 'change profile' and then you can edit information such as avatar, signature, date of birth, e-mail etc. etc.. In fact all the basic profileoptions with personal information. When you press SUBMIT the data will be submitted into the forumsdatabase.

On the website we want to show some profile information of the users. We're thing about things like:
  • Nickname
  • Avatar
  • Profilepicture
  • Postcount

And at the website show some common foruminformation like:
  • Newest members
  • Total members
  • Total posts
  • Latest threads

Maybe you think 'just use vBindex'. But that's not an option because the site is fully handwritten (PHP) and has to be editted to our wishes. What codes do I need to use, are there default scripts, etc. etc..?

Thankyou in advance!!
Reply With Quote
  #2  
Old 05-07-2006, 08:16 AM
bbcentral's Avatar
bbcentral bbcentral is offline
 
Join Date: Apr 2006
Location: Australia
Posts: 96
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi!
I'm doing exactly this right now, I haven't finished but I managed to get the basics working.

Here's a little background info to explain what MY requirements were:
1) Created a site in 2003, became popular so I built my own integrated forum
2) Switched to phpBB2 in 2004/5, but created custom registration and login pages, as well as change profile etc (all running from one user table).
3) Recently purchased vbulletin (hooked on it! ), in the process of rebuilding my main site and the integrated forum.

What I need is:
-Users will register through my own custom page
-Users shouldn't have to create separate accounts for main site and forum
-Users shouldn't have to login twice, changing between main site and forum should be smooth
-Other functions on main site will feed off user table, including downloads (login to download), comments linked to user profiles


I'm guessing this is similar to what you're wanting to do.

The first thing you should try is creating your own login form.
I found some code here for doing that.

Every page on the site should include this code, we'll save it in a file called 'authentication.inc.php':

PHP Code:
<?php

// any functions related to user authentication

// ########## SET PHP ENVIRONMENT 
error_reporting(E_ALL & ~E_NOTICE);

// ###### DEFINE IMPORTANT CONSTANTS 

define('THIS_SCRIPT''add comment');

// #####REQUIRE BACK-END 
chdir($_SERVER['DOCUMENT_ROOT'].'/forum');
require(
'./global.php');
chdir($_SERVER['DOCUMENT_ROOT']);


// define(DIR, $_SERVER['DOCUMENT_ROOT'].'forum');
// chdir($_SERVER['DOCUMENT_ROOT'].'forum');
// require_once($_SERVER['DOCUMENT_ROOT'].'forum/global.php');

// ##### HARD CODE JAVASCRIPT PATHS
$headinclude str_replace('clientscript'$vbulletin->options['bburl'] . '/clientscript'$headinclude);
?>
This assumes your forum is in '/forum/'. This code gives you access to pretty much all of vbulletin, very handy


On any page that has a login form, you have to include this javascript in your head:
HTML Code:
<script type="text/javascript" src="/forum/clientscript/vbulletin_md5.js">
</script>
The actual login form should be something like this:
PHP Code:
<?php

// Check if logged in
if (is_logged_in()) {

    echo 
"Welcome Back, <b>";
    echo 
$vbulletin->userinfo['username'];
    echo 
" !</b>";
    
    
// As we are logged in display logout link
    // Redirect back to the page you are on right now. The page is /downloads/index.php in this case
    // You have a choice between creating your own logout.php file or linking directly to it
    // Here is linking to it:
    
echo "<a href=\"/forum/login.php?$session[sessionurl]do=logout&amp;url=/downloads/index.php&amp;logouthash=$logouthash";
    echo 
$vbulletin->userinfo['logouthash'];
    echo 
"\">";
    echo 
"<font size=\"1\" face=\"verdana\">Log Out</font></a>";
    
// Here is linking to a logout.php file (see below)
    
echo "<a href=/logout.php?redir=/downloads/index.php>Log Out</a>";

}
else {

    
// Not logged in, so display the login form

    
if($error) {
        
// If an error was encountered, display it
        
echo "<font color=red>".$error."</font><br>";
    }
?><form action="/login.php" method="post" onsubmit="md5hash(vb_login_password,vb_login_md5password,vb_login_md5password_utf);">
<label for="username">User:</label> <input type="text" id="username" name="vb_login_username" class="login" />
<label for="password">Pass:</label> <input type="password" id="password" name="vb_login_password" class="login" />
<label for="cb_cookieuser_navbar">Save Login:</label> <input name="cookieuser" type="checkbox" id="cb_cookieuser_navbar" value="1" checked="checked" />
<input type="hidden" name="s" value="<?=$session['sessionhash']?>" />
<input type="hidden" name="do" value="login" />
<input type="hidden" name="vb_login_md5password" />
<input type="hidden" name="vb_login_md5password_utf" />
<input type="hidden" name="url" value="/downloads/index.php" />
<input type="submit" name="login" alt="Login!" /></form>
<?php
}
// End if not logged in

?>
The login form looks quite complex but it's not as terrible as it seems.
Basically when you submit the form, the javascript file we included above takes the value in the vb_login_password field and encrypts it to md5
It then sets vb_login_password to '', so in your login script you are only interested in the md5password value.

The login.php file is something like this:

PHP Code:
<?php

include "authentication.inc.php";

if (
$vbulletin->userinfo['userid']!=0) { // Logged in already (login not required again)

    
if(isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER']) {
        
        
// Redirect back to the page you clicked on the link from
        // Of course, you shouldn't link to 'login.php' when the person is already logged in :)
        
header("Location: ".$_SERVER['HTTP_REFERER']);
    }
    else {
        
        
// If no referer was sent, then go back to the home page
        
header("Location: /");
    }
    
// Another alternative is if already logged in, redirect to the user page (eg account settings, profile etc)
}
else {

    
// User is not logged in
    
if(!empty($_POST)) {

        
// If something was posted to /login.php, then process it
        
        // process the username and password submitted from the login form
        
$username mysql_real_escape_string($_POST['vb_login_username']);
        
$password mysql_real_escape_string($_POST['vb_login_md5password']);

        
// Select the userid from the users table
        // Each user has a field called 'salt', this is used to compare the password
        
$sql  "SELECT `userid` FROM `vb_user` ";
        
$sql .= "WHERE `username`='".$username."' ";
        
$sql .= "AND `password`=md5(CONCAT('".$password."',`salt`)) ";
        
$sql .= "LIMIT 1";
        
        
$rs mysql_query($sql);

        if(
mysql_num_rows($rs) == 1) { 
            
// One row was found, meaning they entered the correct username/password

             
$vbulletin->url=$_POST['url']; // The url to redirect to after login

            
chdir($_SERVER['DOCUMENT_ROOT'].'forum'); // IMPORTANT: Set current directory to forum folder
            
require('./login.php'); // You can't simply load 'forum/login.php', it won't work
            
chdir($_SERVER['DOCUMENT_ROOT']); // SET current dir back to the root folder of site
        
}
        else {
            
// No rows were found, incorrect username or password
            
$error 'Invalid username or password'// error message to be displayed
            
require_once "loginform.inc.php"// redraw the login form, with the error message
        
}

    }
    else {

        
// Else display login form, as nothing was posted, ie the person simply visited /login.php
        
require_once "loginform.inc.php"// Simply the login form seen above
    
}
}
?>


The logout.php file should be something like this:

PHP Code:
<?php

require_once('forum/includes/functions_login.php');

if (
$vbulletin->userinfo['userid']!=0) { // If user is logged in

    
process_logout(); // Log them out

}
// Then redirect or display "you have been logged out" message
// This way if someone visits logout.php when they are logged out already, it will pretend to log them out
// and still redirect correctly
header("Location: /");

?>


I think this covers everything for logging in and out. It should be enough for anyone with a decent understanding of PHP.
I recommend creating some custom functions to speed up the process too, such as:

PHP Code:
<?php
function is_logged_in() {

    global 
$vbulletin;

    if(
$vbulletin->userinfo['userid']!=0) {

        return 
true;
    }

    return 
false;
}
?>
This just says returns true or false depending on if you are logged in or not.
So you can change this:
PHP Code:
<?php
if ($vbulletin->userinfo['userid']!=0) { // If user is logged in

    
process_logout(); // Log them out

}
?>
into this:
PHP Code:
<?php
if (is_logged_in()) { // If user is logged in

    
process_logout(); // Log them out

}
?>

Any total numbers of members should be easy to get using basic SQL:
"SELECT COUNT(userid) FROM vb_users"

As far as the registration pages go, they should be fairly simple, hopefully just fields that you validate and insert into the database.

I haven't done it yet so I can't say. I hope this helped you, having examples to work from certainly helped me get mine working

And one other thing, once you've logged in successfully, load a page with this code:
PHP Code:
<?php
echo "<pre>";
var_dump($vbulletin);
echo 
"</pre>";
?>
This will show you exactly what you have access to just by including the vbulletin core files. Why select it from the database again when it's already there in an array waiting to be used? :P
(BEWARE: This array is HUGE! You will probably have to run a search to find what you're looking for)

Here is a useful array you might want to var_dump:
$vbulletin->userinfo;
You will use this constantly
Reply With Quote
  #3  
Old 05-07-2006, 09:29 AM
Eagle Creek's Avatar
Eagle Creek Eagle Creek is offline
 
Join Date: Jan 2004
Location: Netherlands
Posts: 742
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

bbcentral,

I havn't read your post yet but It looks great!

Thanky ou VERY VERY much in advance and I'll look at it!
And thanks for your time!
Reply With Quote
  #4  
Old 05-08-2006, 05:57 PM
bbcentral's Avatar
bbcentral bbcentral is offline
 
Join Date: Apr 2006
Location: Australia
Posts: 96
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi again, I just got sent an email notification that you'd replied to this topic. I see you've deleted the post though, so I was wondering, should I still answer it?
It was about displaying "users with most posts" and "last 10 posts at forum".
I can help you if you let me know. There already is a mod that can do a lot of these things, but it's up to you if you want to use that method. Personally I prefer doing it like this because I can integrate it easily into my own functions and talk to the database directly. The mod uses the in-built vbulletin methods, eg template parsing, which makes it faster to add to your code.

A good example is VBexternal:
https://vborg.vbsupport.ru/showthread.php?t=83005

I found it wasn't flexible enough for me, but you may find it's exactly what you need
Reply With Quote
  #5  
Old 05-08-2006, 08:21 PM
Eagle Creek's Avatar
Eagle Creek Eagle Creek is offline
 
Join Date: Jan 2004
Location: Netherlands
Posts: 742
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Wow, that vB external (I downloaded a .zip file and read a .txt in it) looks great!

I'm still talking with the other guy. I don't know excactly what the wishes are at this time.

I'll let you know. And thank you thank you again for your help!
Reply With Quote
  #6  
Old 05-12-2006, 07:35 PM
Eagle Creek's Avatar
Eagle Creek Eagle Creek is offline
 
Join Date: Jan 2004
Location: Netherlands
Posts: 742
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That has been very usefull and we're making progress, thank you again!

But; a little question..

When vB displays a date on the forum, it's something we can read. But in the table dates are saved such a strange way?
I mean: Lastpost: 1120519615, joindate: 1120518311 ????

How can we 'translate' this?

EDIT:
Hold on a sec... I've found this topic: https://vborg.vbsupport.ru/showthrea...ate+conversion
Reply With Quote
  #7  
Old 06-14-2006, 12:09 PM
Eagle Creek's Avatar
Eagle Creek Eagle Creek is offline
 
Join Date: Jan 2004
Location: Netherlands
Posts: 742
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok.. Problem..

I want to make a login form. So when you log in, the cookie is nicely placed and you are logged in on the forums.

I changed the template but not I doesn't work anymore .
Reply With Quote
  #8  
Old 06-14-2006, 12:23 PM
bbcentral's Avatar
bbcentral bbcentral is offline
 
Join Date: Apr 2006
Location: Australia
Posts: 96
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm lost.
Do you mean a login form on your main website?
If so, why did you have to change the template?
I don't use that VBExternal thing, I used it to learn the basics but I wrote the majority of it myself. I have my own forms and my own login files.
If you want to see the one I'm temporarily using, go to:
http://www.bluesbrotherscentral.com/
In the top corner you'll see a login box, with username password etc.
The code is:

HTML Code:
<form name="loginform" action="/forum/login.php" onSubmit="md5hash(vb_login_password, vb_login_md5password, vb_login_md5password_utf, 0)" method="POST">
<table width="100%" cellpadding="0" cellspacing="0" style="height:20px;">
<tr>
<td><span class="footer">&nbsp;<input type="text" name="vb_login_username" id="username" class="login" size="12" value="username" onFocus="document.loginform.username.value='';"></span></td>
<td><span class="footer">&nbsp;<input type="password" name="vb_login_password" id="password" class="login" size="12" value="password" onFocus="document.loginform.password.value='';"></span></td>

<td width="40" align="right"><input type="image" name="submitlogin" src="images/login_red.gif" style="border-style:none; width:38px; height:14px;" alt="Login"></td>
<td valign="middle"><span class="footer"><input name="cookieuser" type="checkbox" id="cb_cookieuser_navbar" value="1" checked="checked" class="normal" />Save Login</span></td>
</tr>
</table>
<input type="hidden" name="s" value="" />
<input type="hidden" name="do" value="login" />
<input type="hidden" name="vb_login_md5password" />
<input type="hidden" name="vb_login_md5password_utf" />
<input type="hidden" name="url" value="/" />
</form>
You can remove the table if you like, that's the code copied directly from my website, you can format it however you like.
The most important things are the FORM and INPUT tags, including the 5 hidden fields at the bottom.
The hidden 'url' field (in the example it's set to value="/"), is simply the page to redirect to after you've logged in. Just change it to the current page, ie:

HTML Code:
<input type="hidden" name="url" value="<?=$_SERVER['REQUEST_URI']?>" />
Also, don't forget to include the javascript file in the HEAD of your page. I mentioned it further up in this thread. And you can replace my submit button image with an actual submit button, ie replace
HTML Code:
<input type="image" name="submitlogin" src="images/login_red.gif" style="border-style:none; width:38px; height:14px;" alt="Login" />
with
HTML Code:
<input type="submit" name="submitlogin" value="Login!" />
Reply With Quote
  #9  
Old 06-14-2006, 12:56 PM
Eagle Creek's Avatar
Eagle Creek Eagle Creek is offline
 
Join Date: Jan 2004
Location: Netherlands
Posts: 742
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

HI!

It seems to be working now .

http://www.soccerquest.nl/forum/login_sol.php?styleid=4

Code:
$stylevar[htmldoctype]
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=$stylevar[charset]" />
<meta name="generator" content="vBulletin $vboptions[templateversion]" />
<meta name="keywords" content="$vboptions[keywords]" />
<meta name="description" content="$vboptions[description]" />
<script type="text/javascript">
<!--
var SESSIONURL = "$session[sessionurl_js]";
var IMGDIR_MISC = "$stylevar[imgdir_misc]";
var vb_disable_ajax = parseInt("$vboptions[disable_ajax]", 10);
// -->
</script>

<script type="text/javascript" src="clientscript/vbulletin_global.js"></script>
<script type="text/javascript" src="clientscript/vbulletin_md5.js"></script>
<if condition="$show['popups']"><script type="text/javascript" src="clientscript/vbulletin_menu.js"></script></if>
<if condition="$vboptions['externalrss']"><link rel="alternate" type="application/rss+xml" title="$vboptions[bbtitle] RSS Feed" href="external.php?type=RSS" /></if>
<title>$vboptions[bbtitle]</title>
</head>
<body>

<script type="text/javascript">
<!--
function log_out()
{
	ht = document.getElementsByTagName("html");
	ht[0].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";
	if (confirm('$vbphrase[sure_you_want_to_log_out]'))
	{
		return true;
	}
	else
	{
		ht[0].style.filter = "";
		return false;
	}
}
//-->
</script>

<!-- breadcrumb, login, pm info -->
<body text="#FFFFFF" bgcolor="#000000">

<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
<tr>
	<if condition="$show['member']">
	
	<else />
		
		<td class="alt2" nowrap="nowrap" style="padding:0px">
			
		<!-- login form -->
		<form action="login.php" method="post" onsubmit="md5hash(vb_login_password, vb_login_md5password, vb_login_md5password_utf, $show[nopasswordempty])">
		<script type="text/javascript" src="clientscript/vbulletin_md5.js"></script>
		<table cellpadding="0" cellspacing="$stylevar[formspacer]" border="0">
		<tr>
			<td>
			<input type="text" class="bginput" style="font-size: 11px" name="vb_login_username" id="navbar_username" size="20" accesskey="u" tabindex="101" value="$vbphrase[username]" onfocus="if (this.value == '$vbphrase[username]') this.value = '';" /> 
			<input type="password" class="bginput" style="font-size: 11px" name="vb_login_password" id="navbar_password" size="20" accesskey="p" tabindex="102" /></td>
			<td class="smallfont" colspan="2" nowrap="nowrap"><label for="cb_cookieuser_navbar">
			<input type="checkbox" name="cookieuser" value="1" tabindex="103" id="cb_cookieuser_navbar" accesskey="c" checked />$vbphrase[remember_me] </label><input type="submit" class="button" value="$vbphrase[log_in]" tabindex="104" title="$vbphrase[enter_username_to_login_or_register]" accesskey="s" /></td>
		</tr>
		</table>
		<input type="hidden" name="s" value="$session[sessionhash]" />
		<input type="hidden" name="do" value="login" />		
		<input type="hidden" name="vb_login_md5password" />
		<input type="hidden" name="vb_login_md5password_utf" />
		</form>
		<!-- / login form -->
			
		</td>
		
	</if>	
	
</tr>
</table>
<!-- / breadcrumb, login, pm info -->
</body>
</html>
Why exactly I need the javascript for? To make the MD5 encrypting working?
Reply With Quote
  #10  
Old 06-17-2006, 12:19 AM
bbcentral's Avatar
bbcentral bbcentral is offline
 
Join Date: Apr 2006
Location: Australia
Posts: 96
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yes, the javascript encrypts the password value and saves it in:
<input type="hidden" name="vb_login_md5password" />
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:40 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04375 seconds
  • Memory Usage 2,343KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (5)bbcode_html
  • (8)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete