vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Member Archives (https://vborg.vbsupport.ru/forumdisplay.php?f=202)
-   -   User authenication (https://vborg.vbsupport.ru/showthread.php?t=1296)

06-21-2000 10:02 PM

For those of you wondering how to make restricted pages so that only members of your vB can view them, here is a quick code example to do so. Just require this file as the very first line of whatever file that you want to require a user to have logged into the vB in order to view. Copy this code into a file and save it into the forums directory (same directory as index.php, members.php, etc.) and name it whatever you want.

Its a REALLY simple script that just checks to see if the vB cookie exist. Nothing special at all, but for those of you with no programming experience it's something to work with.

Code:

<?php

/* Here we check to see if the vBulletin cookie exist.
If it doesn't, we prompt the user to either log in or
sign up*/

  if (!$HTTP_COOKIE_VARS["bbuserid"]) {
?>

<table border="0" width="600" cellspacing="0" cellpadding="2" align="center">
  <tr>
    <td valign="top">
<center><h2>Unathorized Access</h2></center>
If the users cookie isn't set, here is where your error message, or whatever message, will be.
        </td>
    <td valign="top" bgcolor="#D2D2D2">
    <form action="index.php" method="post">
      <table border="0" width="100%" cellpadding="2">
        <tr>
          <td width="50%" valign="top"><b>username</b></td>
          <td width="50%" valign="top"><input maxLength="25" name="username" size="10"></td>
        </tr>
        <tr>
          <td width="50%" valign="top"><b>password</b></td>
          <td width="50%" valign="top"><input maxLength="13" name="password" size="10" type="password" value></td>
        </tr>
        <tr>
          <td width="100%" valign="top" colspan="2">
            <p align="center"><input type="submit" value="Login!"></td>
        </tr>
      </table>
      </form>
    </td>
  </tr>
</table>

<?php
  exit;
  }
?>

[Edited by Krucifyx on 06-22-2000 at 07:02 AM]

07-11-2000 01:14 PM

This is great! I think I would incorporate this onto my own site! Thanks krucifyx

10-15-2000 12:09 PM

Thanks for the code. It's given me a good start on password protecting other pages on my site.

However, I'm having some problems.

I need secure pages to check if there's a vb cookie, and if there's not they can sign in using their vb username and password. Then they would see the protected pages.

This code posts login information to the vb index.php file, but after logging in it dumps the user at the forum. I need to have the user dumped at the page they were trying to view. Also, if an incorrect login is used the user is just dumped at the forum.

Any help would be greatly appreciated.

10-15-2000 01:29 PM

I've been out of the vb coding scene for a while but perhaps I can help you out.

What do you mean by it dumping you back to the screen? did you try putting this on all viewed scripts, not just forumdisplay.php?

10-15-2000 01:58 PM

Sorry about my previous post being a little vague.

I'm trying to create a file upload section to my website, but I only want registerd users from my forum to be able to upload. So I'm trying to password protect those upload pages using the vb login and cookies system.

If a vb cookie is already present the user should see the upload page. However, if they aren't logged in, the user should see a page that says, "You need to be a registered user to upload files. Enter username and password or register here." After they login on that screen they should see the upload page.

However, using the code at the top of this thread, the user doesn't see the upload page after logging in -- they are dumped at my forum's index page. An incorrect login has the same result (user is dumped at the forum index page).

In short, if the user is logging in from the forum, they should end up at the forum. If the user is logging in from the upload page, they should end up at the upload page.

Does that make sense?

Sorry for the long post.

[Edited by mferrell on 10-15-2000 at 11:05 AM]

10-21-2000 03:27 AM

Anyone got any pointers for the above post?

10-21-2000 03:43 AM

Code:

<?
require("global.php");

if ($bbuserid == 0)
{
  eval("echo standarderror(\$bbtitle,\"".gettemplate("error_nopermission")."\");");
  exit;
}

if ($bbusername == "" || (isset($bbusername))==0)
{
  $getusername=$DB_site->query_first("SELECT username FROM user WHERE userid=$bbuserid");
  $username=$getusername[username];
  $bbusername = $username;
}
else
{
  $username = $bbusername;
}

// Your Code to ul goes here


10-21-2000 03:00 PM

Thanks! That works but I'm having one problem. When I login with the following code, I'm dumped at my websites index page. How do I get it so that it shows the page that's trying to be viewed?

Here's what I've got now:

__________________________________
<?
chdir($DOCUMENT_ROOT . "/bulletinboard");
require($DOCUMENT_ROOT . "/bulletinboard/global.php3");

if ($bbuserid == 0)
{
eval("echo standarderror(\$bbtitle,\"".gettemplate("error_nop ermission")."\");");
exit;
}

if ($bbusername == "" || (isset($bbusername))==0)
{
$getusername=$DB_site->query_first("SELECT username FROM user WHERE userid=$bbuserid");
$username=$getusername[username];
$bbusername = $username;
}
else
{
$username = $bbusername;
}

// Your Code to ul goes here

?>

<html>
<title>Secure Area</title>
<body><font face=verdana,arial,sans-serif size=2>You should only be able to see this if you're logged in.<p>
</font>
</body>
</html>
____________________________

Thanks again for the help.

10-21-2000 04:22 PM

Well that is supposed to send you to whatever page you were trying to access after logging in.. hmm..

10-21-2000 04:34 PM

Does this file have to be located in the bulletinboard directory? My forum resides in bulletinboard, but the file I'm trying to protect is in the root directory.


All times are GMT. The time now is 10:04 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.00977 seconds
  • Memory Usage 1,736KB
  • 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
  • (2)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete