Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 09-27-2010, 06:34 AM
calexandru calexandru is offline
 
Join Date: Feb 2010
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default login and register from external php page

Hello to all. This is my first post here..i'm using vb a few months ago, and all issues i solved with the mods/articles and other topic, but now...i don't find a {}

I make an sistem on my website, and the login and the registration are using same database like vbulletin forum. The database and the script created by me it's linked very good. (i have a view_active.php ...for online members, total members, online guests and it works very well on my script. All the data that are on vbulletin, are also on my script)

The problem is when i try to login or register from my script. I have:

(a part of) login page:
PHP Code:
/**
 * User not logged in, display the login form.
 * If user has already tried to login, but errors were
 * found, display the total number of errors.
 * If errors occurred, they will be displayed.
 */
if($form->num_errors > 0){
   echo "".$form->num_errors." error(s) found";
}
?>
<form action="process.php" method="POST">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr><td>Nickname:</td><td><input type="text" name="user" maxlength="30" value="<? echo $form->value("user"); ?>"></td><td><? echo $form->error("user"); ?></td></tr>
<tr><td>Parola:</td><td><input type="password" name="pass" maxlength="30" value="<? echo $form->value("pass"); ?>"></td><td><? echo $form->error("pass"); ?></td></tr>
<tr><td colspan="2" align="left"><input type="checkbox" name="remember" <? if($form->value("remember") != ""){ echo "checked"; } ?>>
<font size="2">Tine-ma minte &nbsp;&nbsp;&nbsp;&nbsp;
<input type="hidden" name="sublogin" value="1">
<input type="submit" value="Login"></td></tr>
<tr><td colspan="2" align="left"><br><font size="2">[<a href="forgotpass.php">Ti-ai uitat parola??</a>]</font></td><td align="right"></td></tr>
<tr><td colspan="2" align="left"><br>Nu ai cont? <a href="register.php">Inregistreaza-te!</a></td></tr>
</table>
</form>
(a part of) register page:
PHP Code:
if($form->num_errors > 0){
   echo "<td><font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font></td>";
}
?>
<form action="process.php" method="POST">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr><td>Nickname:</td><td><input type="text" name="user" maxlength="30" value="<? echo $form->value("user"); ?>"></td><td><? echo $form->error("user"); ?></td></tr>
<tr><td>Parola:</td><td><input type="password" name="pass" maxlength="30" value="<? echo $form->value("pass"); ?>"></td><td><? echo $form->error("pass"); ?></td></tr>
<tr><td>Email:</td><td><input type="text" name="email" maxlength="50" value="<? echo $form->value("email"); ?>"></td><td><? echo $form->error("email"); ?></td></tr>
<tr><td colspan="2" align="right">
<td class="row_head">Raspunde corect la intrebare: <?php echo $A."+".$B."="?></td>
<td class="row_text"><input type="text" name="Yanswer" size="3" maxlength="3"></td>
<input type="hidden" name="Answer" value="<?php echo "$C"?>">
<input type="hidden" name="subjoin" value="1">
<input type="submit" value="Inregistreaza"></td></tr>
<tr><td colspan="2" align="left"><a href="index.php">Intoarce-te</a></td></tr>
</table>
</form>
(a part of) process.php
PHP Code:
<?
include("include/session.php");

class Process
{
   /* Class constructor */
   function Process(){
      global $session;
      /* User submitted login form */
      if(isset($_POST['sublogin'])){
         $this->procLogin();
      }

function procLogin(){
      global $session, $form;
      /* Login attempt */
      $retval = $session->login($_POST['user'], $_POST['pass'], isset($_POST['remember']));
      
      /* Login successful */
      if($retval){
         header("Location: ".$session->referrer);
      }
      /* Login failed */
      else{
         $_SESSION['value_array'] = $_POST;
         $_SESSION['error_array'] = $form->getErrorArray();
         header("Location: ".$session->referrer);
      }
   }
   
   /**
    * procLogout - Simply attempts to log the user out of the system
    * given that there is no logout form to process.
    */
   function procLogout(){
      global $session;
      $retval = $session->logout();
      header("Location: index.php");
   }
(a part of) session.php
PHP Code:
/**
    * login - The user has submitted his username and password
    * through the login form, this function checks the authenticity
    * of that information in the database and creates the session.
    * Effectively logging in the user if all goes well.
    */
   
function login($subuser$subpass$subremember){
      global 
$database$form;  //The database and form object

      /* Username error checking */
      
$field "user";  //Use field name for username
      
if(!$subuser || strlen($subuser trim($subuser)) == 0){
         
$form->setError($field"* Username not entered");
      }
      else{
         
/* Check if username is not alphanumeric */
         
if(!eregi("^([0-9a-z])*$"$subuser)){
            
$form->setError($field"* Username not alphanumeric");
         }
      }

      
/* Password error checking */
      
$field "pass";  //Use field name for password
      
if(!$subpass){
         
$form->setError($field"* Password not entered");
      }
      
      
/* Return if form errors exist */
      
if($form->num_errors 0){
         return 
false;
      }

      
/* Checks that username is in database and password is correct */
      
$subuser stripslashes($subuser);
      
$result $database->confirmUserPass($subusermd5(md5($subpass)+$salt));

      
/* Check error codes */
      
if($result == 1){
         
$field "user";
         
$form->setError($field"* Username not found");
      }
      else if(
$result == 2){
         
$field "pass";
         
$form->setError($field"* Invalid password");
      }
      
      
/* Return if form errors exist */
      
if($form->num_errors 0){
         return 
false;
      }

      
/* Username and password correct, register session variables */
      
$this->userinfo  $database->getUserInfo($subuser);
      
$this->username  $_SESSION['username'] = $this->userinfo['username'];
      
$this->userid    $_SESSION['userid']   = $this->generateRandID();
      
$this->userlevel $this->userinfo['userlevel'];
      
      
/* Insert userid into database and update active users table */
      
$database->updateUserField($this->username"userid"$this->userid);
      
$database->addActiveUser($this->username$this->time);
      
$database->removeActiveGuest($_SERVER['REMOTE_ADDR']);

      
/**
       * This is the cool part: the user has requested that we remember that
       * he's logged in, so we set two cookies. One to hold his username,
       * and one to hold his random value userid. It expires by the time
       * specified in constants.php. Now, next time he comes to our site, we will
       * log him in automatically, but only if he didn't log out before he left.
       */
      
if($subremember){
         
setcookie("cookname"$this->usernametime()+COOKIE_EXPIRECOOKIE_PATH);
         
setcookie("cookid",   $this->userid,   time()+COOKIE_EXPIRECOOKIE_PATH);
      }

      
/* Login completed successfully */
      
return true;
   }

   
/**
    * logout - Gets called when the user wants to be logged out of the
    * website. It deletes any cookies that were stored on the users
    * computer as a result of him wanting to be remembered, and also
    * unsets session variables and demotes his user level to guest.
    */
   
function logout(){
      global 
$database;  //The database connection
      /**
       * Delete cookies - the time must be in the past,
       * so just negate what you added when creating the
       * cookie.
       */
      
if(isset($_COOKIE['cookname']) && isset($_COOKIE['cookid'])){
         
setcookie("cookname"""time()-COOKIE_EXPIRECOOKIE_PATH);
         
setcookie("cookid",   ""time()-COOKIE_EXPIRECOOKIE_PATH);
      }

      
/* Unset PHP session variables */
      
unset($_SESSION['username']);
      unset(
$_SESSION['userid']);

      
/* Reflect fact that user has logged out */
      
$this->logged_in false;
      
      
/**
       * Remove from active users table and add to
       * active guests tables.
       */
      
$database->removeActiveUser($this->username);
      
$database->addActiveGuest($_SERVER['REMOTE_ADDR'], $this->time);
      
      
/* Set user level to guest */
      
$this->userlevel GUEST_LEVEL;
   } 
can anybody help me? I think that the problem is on the password field or encryption.... but i can solved it.

Thanks in advance, and sorry for my bad english.
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 10:39 PM.


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.03366 seconds
  • Memory Usage 2,227KB
  • 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
  • (4)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)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