login script python

vibutxvibutx BeginnerLink Clerk
Hey python i like that tutorial that you made for login in but there is one error.

This is what i get everytime i try to log in


Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/vibutx/public_html/login/login.php on line 73

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/vibutx/public_html/login/login.php on line 81
Username and passwords do not match our records

please help

Comments

  • danielneridanielneri WP V.I.P. VPS - Virtual Prince of the Server
    can you post the very top of your code?
    ban1.gif
  • danielneridanielneri WP V.I.P. VPS - Virtual Prince of the Server
    ah nevermind about that...make sure that you entered all your database information correctly :)
    ban1.gif
  • vibutxvibutx Beginner Link Clerk
    everythign is correct. The register works and everythign but when i login.html i put in my info and press enter and this shows up :(
  • lpxxfaintxxlpxxfaintxx Beginner Link Clerk
    i get the SAME EXACT problem.
    Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/lpxxfain/public_html/users/login.php on line 73
    
    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/lpxxfain/public_html/users/login.php on line 81
    Username and passwords do not match our records
    
    <?php
    
    // Connect to the database
    
    $server = "localhost";
    
    $dbuser = "******";
    
    $dbpass = "******";
    
    $dbname = "******";
    
    mysql_connect($server,$dbuser,$dbpass) or die ("Could not establish connection"); // make connection
    
    mysql_select_db($dbname); // select database
    
    
    
    // convert posted info to easy to use variables
    
    $user = $_REQUEST['username'];
    
    $pass = $_REQUEST['password'];
    
    
    
    // strip away any dangerous tags
    
    $user=strip_tags($user);
    
    $pass=strip_tags($pass);
    
    
    
    // remove spaces from variables
    
    $user=str_replace(" ","",$user);
    
    $pass=str_replace(" ","",$pass);
    
    
    
    // remove escaped spaces
    
    $user=str_replace("%20","",$user);
    
    $pass=str_replace("%20","",$pass);
    
    
    
    // add slashes to stop hacking
    
    $user=addslashes($user);
    
    $pass=addslashes($pass);
    
    
    
    // encrypt password into md5 (random 32 characters)
    
    $pass=md5($pass);
    
    
    
    // search database to check for user
    
    $request = "SELECT * FROM users WHERE password='".$pass."' AND username='".$user."'";
    
    
    
    // hand over the request
    
    $results = mysql_query($request,$conn);
    
    
    
    
    
    // if mysql returns any number of rows great than 0 then there is a succesful login
    
    if(mysql_num_rows($results))
    
    {
    
    // get users id
    
    $getid = "SELECT * FROM users WHERE username='".$user."' LIMIT 1";
    
    $getidexec = mysql_query($getid);
    
    
    
    while($r=mysql_fetch_array($getidexec)){
    
    $userid = $r[userid];
    
    }
    
    // set a cookie
    
    setcookie( "userid", "$userid", time()+3600, "/", "", 0 );
    
    echo "User Logged in.<br><br><a href=\"index.php\">Continue...</a>";
    
    
    
    }
    
    else // only happens if not a succesful username and password match
    
    {
    
    // login failed so display error message and kill script
    
    die("Username and passwords do not match our records");
    
    }
    
    ?>
    


    That is the code used to make the login.php... any ideas?? BTW, i changed the DB info to **** for security reasons
  • danielneridanielneri WP V.I.P. VPS - Virtual Prince of the Server
    instead of using variables to connect to the database,

    mysql_connect(your_server,your_username,your_password) or die ("Could not establish connection"); // make connection

    mysql_select_db(your_db); // select database

    just put the info directly into the statement
    ban1.gif
  • TheDonkeyTheDonkey Junior Member Shared Hoster
    Hey I just read the tut and I’m thinking of implementing this into part of a webpage of mine.

    See this is what I want to do and I have a few questions to see if this will work with what I am trying to do.

    I have a strategy section and I would like it so that non registered users could only limited amounts of the section and for the real juicy stuff you need to be a site user. What I’m wondering is will this script work with .htaccess files in order to keep people out of directories of the pages. In other words I don’t want people to be able to link to the address of a certain piece of content and bypass all the login/registration scripting.

    Secondly I was curious if this scripting is cable of being used with the database I use for my phpBB. In other words people only need to register on the site once and will be able to access all content.

    Finally, this is only an idea I have and I'm not very good with php but rather proficeint with html/xhtml (I have limited experince with other languages as well). I have started to learn php and think this would help with the learning of the language and provide a nice feature to my site.

    all comments are welcome. Again I havent started the scripting yet so maybe I might be able to answer most these questions myself.

    edit-
    Ok so I think i figured out how to prevent the access to other parts of the site.... silly me had blinders on with the index.php.

    That is just a generic php file. Like if you wanted to have an index.php file for the intial content section and then you had that linked to a say page2.php all you would need to do is place the login verification code in that page (page2.php), right?

    Still wondering about the phpBB database usage though :)

    Also can I place the php login varification into an html/xhtml file or does it have to be a php file strictly?

    BTW, Python....awsome job with the tuts man ;)

    Thanks,
    Capt. D
    F18_468x60.jpg
  • danielneridanielneri WP V.I.P. VPS - Virtual Prince of the Server
    well as far as phpbb is...you can use the phpbb membership system and integrate it into your whole site. all you have to do is include a small script at the top of your document:
    <?php
    define('IN_PHPBB',true);
    
    $phpbb_root_path = "./"; // set path to phpBB files
    include($phpbb_root_path . 'extension.inc');
    include($phpbb_root_path . 'common.'.$phpEx);
    
    //
    // Start session management
    //
    $userdata = session_pagestart($user_ip, PAGE_LOGIN); // initiate session
    init_userprefs($userdata); // load user prefs
    //
    // End session management
    //
    $page_title = "Title of Page Goes Here";
    
    
    $userid = $userdata['user_id'];
    $sql = "SELECT * FROM " . USER_GROUP_TABLE . " WHERE user_id = '$userid'";
    $result = $db->sql_query($sql);
    $isauth = 0;
    while ($row = $db->sql_fetchrow($result))
    {
    if ($row['group_id'] == 'insert_group_id_here' || $row['group_id'] == 'insert_group_id_here')
    {
    $isauth = 1;
    }
    }
    
    
    
    
    if($userdata['session_logged_in'])
    { // user is logged in
    
    include($phpbb_root_path . 'includes/page_header.'.$phpEx);
    if ($isauth == '1')
    {
    Insert content here
    }
    else
    {
    message_die(GENERAL_ERROR, "You do not have permission to access this page");
    }
    }
    else
    { // not logged in
    header('Location: ' . append_sid($phpbb_root_path.'login.'.$phpEx.'?redirect='.basename($HTTP_SERVER_VARS['PHP_SELF']), true));
    }
    
    include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
    
    ?>
    



    this should help you out some...you do need to change some of the details though. if you have any problems, feel free to pm me :)
    ban1.gif
  • danielneridanielneri WP V.I.P. VPS - Virtual Prince of the Server
    Also can I place the php login varification into an html/xhtml file or does it have to be a php file strictly?


    You can create a html file and then rename it php, insert the php code wherever you want it to appear, and voila

    for example if you had a normal index.html file:

    [PHP]
    <HTML>
    <HEAD>
    </HEAD>
    <BODY>
    <A>HI THIS IS MY BODY CONTENT :)</A>
    <?PHP>
    //INSERT PHP LOGIN CODE HERE
    ?>
    </BODY>
    </HTML>
    [/PHP]


    EDIT:

    YOU HAVE TO RENAME IT AS A PHP FILE FOR THE CODE TO WORK
    ban1.gif
  • TheDonkeyTheDonkey Junior Member Shared Hoster
    Oh my I cant wait to get out of the office and onto my home computer to try this all out :)

    edit-
    So wait I can just place the phpBB code into a webpage as stated above and rename it to a php file. Thus place the login verification and what not....hmmm but wait is that phpBB code the login or the verification or is it both???

    OK i think i might have wraped my hands around this...

    The phpBB script simply checks to see if the user is logged in and if they are not it redirects them to the phpBB login page. Then once logged in it will redirect them to the content. Is this correct?

    Thanks bud
    Capt. D
    F18_468x60.jpg
  • danielneridanielneri WP V.I.P. VPS - Virtual Prince of the Server
    yeah i think thats what it does.

    i know that if the user is not logged in, it leads them to the login page. although im not sure what you mean by verification
    ban1.gif
  • jwcookjwcook Beginner Link Clerk
    I was wondering if it would be pheasable to put the php code into include files? Something like login.inc would include the code from login.php... I know this usually works with asp and javascript; not sure about php... Also, I ran through all of your 3 part tut on Membership scripts Python; I keep getting a Registration Failed error; any idea how I can fix this?

    Despite this little issue, I found your tuts to be very insightfull.
Sign In or Register to comment.