vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Checking vB usergroup from non-vb page (https://vborg.vbsupport.ru/showthread.php?t=112624)

lightnb 04-10-2006 05:24 AM

Checking vB usergroup from non-vb page
 
What is the php code to use to see if a user is logged into vb, and to see what group they are a member of, from a non-vB PHP page, within the same domain?

RS_Jelle 04-10-2006 09:07 AM

Have a look at this tutorial ;)

lightnb 04-10-2006 09:18 AM

Thanks. I'll try it, but it'd be cool if there were a simpler version... all i really need is somthing like:

PHP Code:

<?PHP

require_once('http://www.mysite.com/livexchange/forums/global.php');



// IF THE USER IS LOGGED IN
if ($bbuserinfo[userid])
{
echo 
'The user is logged in!';

}
// ELSE THEY ARE NOT
else
{
echo 
'The user is not logged in!';
}

?>

I have a form on my site that uploads to a database, and I want to use the vB login system as a cheap way of making sure only certain people can access it.

RS_Jelle 04-10-2006 09:43 AM

Read the full tutorial, everything is in there (and a lot more) and it's very easy. :)

You need something like this:
PHP Code:

<?php

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

// ##################### DEFINE IMPORTANT CONSTANTS #######################
// change the line below to the actual filename without ".php" extention.
// the reason for using actual filename without extention as a value of this constant is to ensure uniqueness of the value throughout every PHP file of any given vBulletin installation.

define('THIS_SCRIPT''test');

// ########################## REQUIRE BACK-END ############################
chdir('/home/site/public_html/livexchange/forums/global.php');
require_once(
'./global.php');  

// #################### HARD CODE JAVASCRIPT PATHS ########################
$headinclude str_replace('clientscript'$vbulletin->options['bburl'] . '/clientscript'$headinclude);

// ########################################################################
// ######################### START MAIN SCRIPT ############################
// ########################################################################

if (!is_member_of($vbulletin->userinfo6) AND !is_member_of($vbulletin->userinfo7))
{
        
print_no_permission();
}

// Your upload code here

?>

Probably you need to change this code (have a look at your config.php for it):
PHP Code:

chdir('/home/site/public_html/livexchange/forums/global.php'); 

Also change the script name and the usergroups to the correct ones for your script.

lightnb 04-10-2006 09:57 AM

Thanks, got the test page working. :)

Well, it worked as a stand-alone page, but when i tried integrating it into another page, I get an error:

Code:

Fatal error: Call to a member function unlock_tables() on a non-object in /home/.sites/22/site13/web/livexchange/forums/includes/functions.php on line 4366

here's what I have:

PHP Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
    <title>Glossary Administration</title>
</head>

<body>

<h2 align="left">Glossary Administration</h2>

<p align="left">



<?php

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

// ##################### DEFINE IMPORTANT CONSTANTS #######################
// change the line below to the actual filename without ".php" extention.
// the reason for using actual filename without extention as a value of this constant is to ensure uniqueness of the value throughout every PHP file of any given vBulletin installation.

define('THIS_SCRIPT''admin');

// ########################## REQUIRE BACK-END ############################
chdir('/pathtosite/forums');
require_once(
'./global.php');  

// #################### HARD CODE JAVASCRIPT PATHS ########################
$headinclude str_replace('clientscript'$vbulletin->options['bburl'] . '/clientscript'$headinclude);

// ########################################################################
// ######################### START MAIN SCRIPT ############################
// ########################################################################

if (!is_member_of($vbulletin->userinfo6) AND !is_member_of($vbulletin->userinfo7))
{
        
print_no_permission();
}

echo 
'You are logged in!<br>';

// Your upload code here

$configfile "config.php";
require 
$configfile;
$db mysql_connect("$host""$username""$password");
mysql_select_db("$databasename"$db);

//Add word
if($action=="add")
{
if(
$word&&$definition)
{
$addWord=mysql_query("INSERT INTO `mdglossary` (`word`, `definition`) VALUES ('$word', '$definition')"$db);
if(
$addWord)
{
echo 
"The word $word and it's definition has been successfully added to the database";
}
if(!
$addWord)
{
echo 
"There has been an error in adding the word $word";
}
}
if(!
$word||!$definition)
{
echo 
"
<form name=\"mdglossary\" action=\"
$PHP_SELF\" method=\"post\">
<b>Word</b>
<br>
<i>The word you want adding</i>
<br>
<input name=\"word\" type=\"text\" value=\"\" maxlength=\"40\">
<br>
<br>
<b>Definition</b>
<br>
<i>The definition of the word</i>
<br>
<textarea name=\"definition\" rows=\"6\" cols=\"50\" ></textarea>
<br>
<input name=\"action\" type=\"hidden\" value=\"add\">
<input type=\"submit\" value=\"Add\">&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"reset\" value=\"Reset\">
</form>
"
;
}
}

//Edit word
if($action=="edit")
{
if(
$word&&$definition)
{
$updateIt=mysql_query("UPDATE mdglossary SET word='$word', definition='$definition' WHERE id='$id'",$db);
if(
$updateIt)
{
echo 
"The word $word has been successfully updated";
}
if(!
$updateIt)
{
echo 
"There has been an error in updating the word $word";
}
}
if(!
$word&&!$defintion)
{
$getInfo=mysql_query("SELECT * FROM `mdglossary` WHERE id=$id",$db);
if(
$theInfo=mysql_fetch_array($getInfo))
{
echo 
"
<form name=\"mdglossary\" action=\"
$PHP_SELF\" method=\"post\">
<b>Word</b>
<br>
<i>The word you want editing</i>
<br>
<input name=\"word\" type=\"text\" value=\""
;
printf($theInfo["word"]);
echo 
"\" maxlength=\"40\">
<br>
<br>
<b>Definition</b>
<br>
<i>The definition of the word</i>
<br>
<textarea name=\"definition\" rows=\"6\" cols=\"50\" >"
;
printf($theInfo["definition"]);
echo 
"</textarea>
<br>
<input name=\"action\" type=\"hidden\" value=\"edit\">
<input name=\"id\" type=\"hidden\" value=\"
$id\">
<input type=\"submit\" value=\"Update\">&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"reset\" value=\"Reset\">
</form>
"
;
}
else
{
echo 
"There has been an error";
}
}
}

//Delete word
if($action=="delete")
{
if(
$check=="yes")
{
$deleteIt=mysql_query("DELETE FROM mdglossary WHERE id=$id",$db);
if(
$deleteIt)
{
echo 
"The word has successfully been deleted";
}
if(!
$deleteIt)
{
echo 
"There has been an error whilst the word was being deleted. Please try again";
}
}
else
{
$getDeleteInfo=mysql_query("SELECT * FROM mdglossary WHERE id='$id'",$db);
$deleteInfo=mysql_fetch_array($getDeleteInfo);
echo 
"Are you sure you want to delete the following word?<br>";
echo 
"
<dl>
<dt><b>
"
;
printf($deleteInfo["word"]);
echo 
"
</b></dt>
<dd>
"
;
printf($deleteInfo["definition"]);
echo 
"
</dd>
</dl>
"
;
echo 
"<br><a href=\"$PHP_SELF?action=delete&id=$id&check=yes\">Yes</a>&nbsp;&nbsp;&nbsp;<a href=\"$PHP_SELF?action=main\">No</a>";
}
}

//Get Code
if($action=="getcode")
{
$getInfo=mysql_query("SELECT * FROM `mdglossary` WHERE id=$id",$db);
if(
$getCode=mysql_fetch_array($getInfo))
{
$lowWord=strtolower($getCode["word"]);
echo 
"The code that you can copy and paste the word - <b>";
printf($getCode["word"]);
echo 
"</b> - into your pages is:<br><br>";
echo 
"<form><textarea cols=\"50\" rows=\"5\">";
echo 
"&lt;a href=\"$roottoglossary?word=$lowWord\" class=\"glossary\" title=\"Click here to find out what this word means\"&gt;";
printf($getCode["word"]);
echo 
"&lt;/a&gt;";
echo 
"</textarea></form>";
echo 
"Example:<br><br><a href=\"$roottoglossary?word=$lowWord\" class=\"glossary\" title=\"Click here to find out what this word means\">";
printf($getCode["word"]);
echo 
"</a>";
}
else
{
echo 
"Sorry, there has been an error";
}
}



//Add wordpack
if($action=="addwordpack")
{
if(
$packname)
{
echo 
"Include file:<br>";
if(include (
$packname))
{

$insertPack=mysql_query($insertLines);

if(
$insertPack)
{
echo 
"the pack has been added successfully<br>";
}
else
{
echo 
"Sorry there has been an error<br>";
}
}
else
{
echo 
"Sorry, there has been a problem opening $packname. Check that you have uploaded it correctly and that you have typed in the name correctly.";
echo 
"
<br>
<form name=\"pack\" action=\"
$PHP_SELF\" method=\"get\">
<input name=\"packname\" type=\"text\" value=\"\">
<input name=\"action\" type=\"hidden\" value=\"addwordpack\">
<br>
<input type=\"submit\" value=\"Add\">
</form>
"
;
}
$rep "<br>(";
$insertLines ereg_replace("\("$rep$insertLines);
echo 
$insertLines;
}
else
{
echo 
"Type in the filename of the wordpack you want to add. (ie <i>internetpack.php</i>)";
echo 
"
<br>
<form name=\"pack\" action=\"
$PHP_SELF\" method=\"get\">
<input name=\"packname\" type=\"text\" value=\"\">
<input name=\"action\" type=\"hidden\" value=\"addwordpack\">
<br>
<input type=\"submit\" value=\"Add\">
</form>
"
;
}
}

//Help
if($action=="help")
{
echo 
"For up-to-date help, information and upgrades to MD Glossary, as well as other new programs to use on your website, visit <a href=\"http://www.matthewdingley.co.uk/programs/glossary/\" target=\"_blank\">MD Web</a>";
}

//Main menu
if($action=="main"||!$action)
{
echo 
"<a href=\"$PHP_SELF?action=add\">Add a word</a>&nbsp;&nbsp;&nbsp;<a href=\"$PHP_SELF?action=help\">Help</a><br><br>";
echo 
"You can also go to <a href=\"www.matthewdingley.co.uk/programs/news/\">MD Web</a> and download a wordpack. This will have loads of pre-done words for you to use. When you have downloaded the
word pack, click <a href=\"
$PHP_SELF?action=addwordpack\">here</a> to install it.";
$getWords=mysql_query("SELECT * FROM mdglossary ORDER BY word");
if(
$getWordArray=mysql_fetch_array($getWords))
{
echo 
"<table width=\"90%\" cellspacing=\"8\" cellpadding=\"0\">";
do
{
echo 
"
       <tr>
              <td>
           <dl>
           <dt><b>
           "
;
printf($getWordArray["word"]);
           echo 
"
           </b></dt>
           <dd>
           "
;
printf($getWordArray["definition"]);
           echo 
"
           </dd>
           </dl>
           </td>
           
           <td>
           <a href=\"
$PHP_SELF?action=edit&id=";
printf($getWordArray["id"]);
           echo 
"
           \">Edit</a>
           </td>
           
           <td>
           <a href=\"
$PHP_SELF?action=delete&id=";
printf($getWordArray["id"]);
           echo 
"
           \">Delete</a>
           </td>
           <td>
           <a href=\"
$PHP_SELF?action=getcode&id=";
printf($getWordArray["id"]);
           echo 
"
           \">Get&nbsp;code</a>
           </td>
        </tr>
"
;
}
while(
$getWordArray=mysql_fetch_array($getWords));
echo 
"</table>";
}
else
{
echo 
"<br><br>There are currently no words in the database. <a href=\"$PHP_SELF?action=add\">Add a word</a>";
}
}
if(
$action=="add"||$action=="edit"||$action=="delete"||$action=="getcode"||$action=="install"||$action=="addwordpack"||$action=="help")
{
echo 
"<br><br><a href=\"$PHP_SELF?action=main\">Main menu</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"$PHP_SELF?action=add\">Add a word</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"$PHP_SELF?action=help\">Help</a>";
}
?>
</body>
</html>



All times are GMT. The time now is 12:02 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.01287 seconds
  • Memory Usage 1,844KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (4)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete