Announcement

Collapse
No announcement yet.

Simple User Login

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Simple User Login

    Hmm ok, i've searched this forum for a user login kinda php script. But my attempts to were to no avail. Im not super great in php. But how would i make a simple login on a non-vB page that would check to see if their logged in and keep them logged in globally?
    http://img66.exs.cx/img66/4535/astgmail.gif

  • #2
    Originally posted by Asterik
    Hmm ok, i've searched this forum for a user login kinda php script. But my attempts to were to no avail. Im not super great in php. But how would i make a simple login on a non-vB page that would check to see if their logged in and keep them logged in globally?
    Is it safe to assume that you want to use the vB login on the non-vB pages, rather than creating an entirely new members database and login system?

    Comment


    • #3
      lol yes :P i'd use the same tables n stuff as vB3 and all that stuff
      http://img66.exs.cx/img66/4535/astgmail.gif

      Comment


      • #4
        Originally posted by Asterik
        lol yes :P i'd use the same tables n stuff as vB3 and all that stuff
        On each non-vB page, include the following PHP code:

        Code:
        [size=2]chdir([/size][size=2][color=#0000f0]'./yourforumdirectory (relative to the non-vB page)/'[/color][/size][size=2]);[/size]
        [size=2][b]require[/b]([/size][size=2][color=#0000f0]'global.php'[/color][/size][size=2]);[/size]
        This will get information from vB's 'user' table based on the user's cookie or session, and store it in an array within the variable $bbuserinfo.

        Displaying $bbuserinfo["userid"] on a non-vB page, for instance, will display the logged-in user's member id number. If the user is a guest, it will default to "0". Other $bbuserinfo examples include: $bbuserinfo["username"] to display the user's username, and $bbuserinfo["email"] to display their e-mail address. This will work for every field within the 'user' table of your vBulletin database by substituting any field name (userid, usergroupid, etc.) in place of "fieldname" in $bbuserinfo["fieldname"].

        If you would like to write a simple PHP script to detect a login, try a simple conditional like:

        Code:
        [size=2]if ($bbuserinfo["userid"]!=0)[/size]
        [size=2]{[/size]
        // If the user's userid is not 0, and therefore, is not a guest
        [size=2]echo ("You are logged in, ".$bbuserinfo["username"]."");[/size]
        [size=2]}[/size]
        [size=2]else[/size]
        [size=2]{[/size]
        [size=2]// If the user is a guest[/size]
        echo ("You are not logged in. Please login or register");
        [size=2]}[/size]
        Remember to call the global.php file as outlined above. Let me know if you have any further questions.
        Last edited by inthezone; Tue 4 Nov '03, 3:58pm.

        Comment


        • #5
          ok, i looked at the login.php file and used some code from that and it works! but how would i hide the form once they're signed in? and show the stats there or somethin?
          Last edited by Asterik; Tue 4 Nov '03, 5:20pm.
          http://img66.exs.cx/img66/4535/astgmail.gif

          Comment


          • #6
            Originally posted by Asterik
            ok 1 more question, how would i set the form up exactly to talk to vBulletin n stuff?
            You mean a login form with fields for username and password, and a submit button?

            Comment


            • #7
              lol read post again, i edited like right when u were respondin
              http://img66.exs.cx/img66/4535/astgmail.gif

              Comment


              • #8
                Originally posted by Asterik
                ok, i looked at the login.php file and used some code from that and it works! but how would i hide the form once they're signed in? and show the stats there or somethin?
                A PHP conditional like this should work:

                Code:
                if ($bbuserinfo["userid"]!=0)
                {
                // The user's ID # is not equal to 0, and therefore, they are not a guest
                 
                echo ("
                Welcome back, ".$bbuserinfo["username"].".<br />
                You have made ".$bbuserinfo["posts"]." post(s).
                ");
                 
                }
                else
                {
                // The user must be a guest, since their ID # is 0
                 
                <Insert HTML code for login form here. Remember to format the tags so that
                they are compliant with PHP, e.g. add a slash before quotation marks and
                apostrophes in HTML tags, so that type="text" will be type=\"text\">
                 
                }

                Comment


                • #9
                  Do you know how to make this work on pages that have existing mysql connections?

                  If I apply the trick you mentioned above, the connection to the forums database "takes over" and all the other php/mysql code the page is using stops working.

                  Is there any way I could "Strip out" some php code from vB to "just" check for the session/login information?



                  I'm using vB 2.2.3 (I know, it's old, but hey I hacked it enough to be scared to upgrade )

                  Thanks in advance

                  -mano
                  design and technology / mano1.com
                  resource and community for musicians / FutureProducers.com

                  Comment

                  widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                  Working...
                  X