elevenmil
Apr 5 2005, 07:44 AM
| | Although I'm doing some tweaking, I have finally got just about everything down in developing a login feature to my website, but just one problem. The session terminates too quickly. For instance, someone will be instructed to login, and after browsing a couple pages, it'll come up again that the user is not logged in. In addtion, this occurs frequently but not all the time. What can I do that will eliminate this inconvience to my viewers? |
Reply
karlo
Apr 5 2005, 11:06 AM
QUOTE(elevenmil @ Apr 5 2005, 03:44 PM) Although I'm doing some tweaking, I have finally got just about everything down in developing a login feature to my website, but just one problem. The session terminates too quickly. For instance, someone will be instructed to login, and after browsing a couple pages, it'll come up again that the user is not logged in. In addtion, this occurs frequently but not all the time. What can I do that will eliminate this inconvience to my viewers? Hmmm... use setcookie don't use session id's or go to http://www.google.com/search?q=sessions+site:php.net
Reply
elevenmil
Apr 6 2005, 01:37 AM
This is my login.php...your reply confused me a lot but what would I change here...? If nothing is changed here is what your talking about in my register.php? login.php CODE <?
/** * Checks whether or not the given username is in the * database, if so it checks if the given password is * the same password in the database for that user. * If the user doesn't exist or if the passwords don't * match up, it returns an error code (1 or 2). * On success it returns 0. */ function confirmUser($username, $password){ global $conn; /* Add slashes if necessary (for query) */ if(!get_magic_quotes_gpc()) { $username = addslashes($username); }
/* Verify that user is in database */ $q = "select password from users where username = '$username'"; $result = mysql_query($q,$conn); if(!$result || (mysql_numrows($result) < 1)){ return 1; //Indicates username failure }
/* Retrieve password from result, strip slashes */ $dbarray = mysql_fetch_array($result); $dbarray['password'] = stripslashes($dbarray['password']); $password = stripslashes($password);
/* Validate that password is correct */ if($password == $dbarray['password']){ return 0; //Success! Username and password confirmed } else{ return 2; //Indicates password failure } }
/** * checkLogin - Checks if the user has already previously * logged in, and a session with the user has already been * established. Also checks to see if user has been remembered. * If so, the database is queried to make sure of the user's * authenticity. Returns true if the user has logged in. */ function checkLogin(){ /* Check if user has been remembered */ if(isset($_COOKIE['cookname']) && isset($_COOKIE['cookpass'])){ $_SESSION['username'] = $_COOKIE['cookname']; $_SESSION['password'] = $_COOKIE['cookpass']; }
/* Username and password have been set */ if(isset($_SESSION['username']) && isset($_SESSION['password'])){ /* Confirm that username and password are valid */ if(confirmUser($_SESSION['username'], $_SESSION['password']) != 0){ /* Variables are incorrect, user not logged in */ unset($_SESSION['username']); unset($_SESSION['password']); return false; } return true; } /* User not logged in */ else{ return false; } }
/** * Determines whether or not to display the login * form or to show the user that he is logged in * based on if the session variables are set. */
function displayLogin(){ global $logged_in; if($logged_in){ ?> This is a new login confirmation display You are logged in <b><? echo $_SESSION['username']; ?></b>, have fun. <a href="logout.php">Logout</a><br><br>
Thank you. You may close this window and access the selected pages or return back to <a href="index.html">Home</a> <? } else{ ?>
<h1>Login</h1><br><br> There are current problems with the login feature...when logging in please use the "remember me" feature to avoid any inconviences...<br><br><br> <form action="" method="post"> <table align="left" border="0" cellspacing="0" cellpadding="3"> <tr><td>Username:</td><td><input type="text" name="user" maxlength="30"></td></tr> <tr><td>Password:</td><td><input type="password" name="pass" maxlength="30"></td></tr> <tr><td colspan="2" align="left"><input type="checkbox" name="remember"> <font size="2">Remember me next time</td></tr> <tr><td colspan="2" align="right"><input type="submit" name="sublogin" value="Login"></td></tr> <tr><td colspan="2" align="left">Not yet registered? Click here to <a href="register.php">Register</a></td></tr> </table> </form>
<? } }
/** * Checks to see if the user has submitted his * username and password through the login form, * if so, checks authenticity in database and * creates session. */ if(isset($_POST['sublogin'])){ /* Check that all fields were typed in */ if(!$_POST['user'] || !$_POST['pass']){ die('You didn\'t fill in a required field.'); } /* Spruce up username, check length */ $_POST['user'] = trim($_POST['user']); if(strlen($_POST['user']) > 30){ die("Sorry, the username is longer than 30 characters, please shorten it."); }
/* Checks that username is in database and password is correct */ $md5pass = md5($_POST['pass']); $result = confirmUser($_POST['user'], $md5pass);
/* Check error codes */ if($result == 1){ die('That username doesn\'t exist in our database.'); } else if($result == 2){ die('Incorrect password, please try again.'); }
/* Username and password correct, register session variables */ $_POST['user'] = stripslashes($_POST['user']); $_SESSION['username'] = $_POST['user']; $_SESSION['password'] = $md5pass;
/** * 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 md5 encrypted password. We set them both to * expire in 100 days. Now, next time he comes to our site, we will * log him in automatically. */ if(isset($_POST['remember'])){ setcookie("cookname", $_SESSION['username'], time()+60*60*24*100, "/"); setcookie("cookpass", $_SESSION['password'], time()+60*60*24*100, "/"); }
/* Quick self-redirect to avoid resending data on refresh */ echo "<meta http-equiv=\"Refresh\" content=\"0;url=$HTTP_SERVER_VARS[PHP_SELF]\">"; return; }
/* Sets the value of the logged_in variable, which can be used in your code */ $logged_in = checkLogin();
?>
Reply
Similar Topics
Keywords : login registration mysql problems session terminates quickly- Please Explain Me Mysql
- How do i insert information into this config: (4)
- Mysql Database Size
- related to the free database space (6)
hi all! this is my first post /biggrin.gif' border='0' style='vertical-align:middle'
alt='biggrin.gif' /> and i have a doubt, how much mysql space i am allowed to use... i mean how
much is available for my free account...
Updating Website, Ftp Problems
- (5)
2 problems! a) how do i update my website??? like if i make changes to the code of say my
index.html page, how do i make these changes take place on the website online?? /cool.gif"
style="vertical-align:middle" emoid="B)" border="0" alt="cool.gif" /> how come my ftp uploads my
files to a file under my public_html folder but also under a folder with my user name
(public_html/username ) ??? this makes it so the url of my site isnt www.abc.trap17.com anymore
but www.abc.trap17.com/username/ ---- this makes no sence!!...
How To Get Credits Quickly
- credit points quickly (19)
Does anybody how to get credit poiints quickly ... It is boring to wait two days and post tens of
articles until you get 10 points and then be qualified to get free hosting... thank you...
Login Script For Vbulletin.
- (8)
For some reason when I try to logon from the main page it doesnt work, it just brings me to the
forums unlogged. Anyone here have any ideas whats wrong with my coding? Heres the webpage:
www.ageofilluminati.com Heres the coding im Using: QUOTE
Forgot password? Register for free! ...
Mysql Database Space
- (3)
How much space does Trap17 offer for MySQL database in terms of MB? I need to know because I intend
to host a forum for my classmates and it will be a gathering place for us. We are all ex students of
a school so the forum will be a handy hangout place to get info and status about each other, since
we're all seperated now. So, the forum takes up 150KB in my database and its increasing daily
due to increasing number of posts and members. The day will come when it hits the 12 MB database
space my current free host offers. So, any input or help is very much appreciate...
New Hosting Account Problems
- Can't find cpanel login page (11)
QUOTE Xisto Processing.. Please wait!. Do not hit RELOAD or BACK.. Username Validated.
Connecting to Database... Database Connection Established. Validating username and password..
Username Validated. Checking permissions.. Permission granted. Preparing data for Creating Account..
Approved for trap17_Beta.. Checking, if username is unique. Username seems to be unique. All Data
Confirmed. Account information Ready. Stand-by, Trying to connect to server and create account..
This might take very long time. Please be patient... CREATING ACCOUNT... REQUEST SENT. WAIT...
Some Hosting Problems..
- (8)
Well.. just by the looks of it, i am not hosted, and i ahve lost my domain.. my account.... have
about.. neg 25 credits, (lollol) and then like.. a day later or something, i wasn't hosted
anymore, i mean, i thought the hosting terminated at neg 30? and i had a free domain, so i lost a
lot, /sad.gif" style="vertical-align:middle" emoid=":(" border="0" alt="sad.gif" />...
Cpanel Login Trouble!
- (4)
Plz help me out with my cpanel mess!! with correct username and psswrd i cannot log in...was
working fine sme days bck when i purchased it!! i`m losing business as i cannot reply to
emails as they woudn`t open either!!! whats this mess?? I tried to log in with my
default psswrd which was mailed to me!! lemme outta dis people!!!!
/unsure.gif" style="vertical-align:middle" emoid=":unsure:" border="0" alt="unsure.gif" /> link to
my website is https://sun.host.ac:2083/frontend/x3/index.html ...
Mysql
- administration (5)
QUOTE Using your MySQL administration tool that your web host has, check to see if the table was
created correctly. Afterwards, try creating a few of your own tables to be sure that you have gotten
the hang of it. Where is the MySQL administration tool on trap17 O_o, i can't find it....
Can't Login
- (8)
Hey guys, I am trying to log into my Trap17 account, but can't seem to get in. I may have just
forgot my password, but I have it written down, and it worked a few times before :/ I did recently
change my domain, does that effect the username? If it is my fault and I just forgot something, is
there a place I can do the "Forgot Password?" thing, and have my user/pass emailed to me? Thanks in
advance to any replies /smile.gif" style="vertical-align:middle" emoid=":)" border="0"
alt="smile.gif" />...
I Can't Login With Firefox And Other Problems
- (7)
I am having a problem: When trying to login with firefox, I just can't, it takes me back to the
login page without being loged in. I am wondering why? Plus while logging in with IE6, The forums
main page is always displayed the same. Not even the forum but the whole forum. I can't see my
posts nor my credits. And PMs inclueded. I tried deleting all offline pages, setting up the cookies
and deleting all my history sites, but none of this work. Perhaps it's because I newly installed
Google Web accelerator. I don't need it, so I am thinking of uninstalling i...
External Access To Mysql Database
- game plugin (0)
hello guys, me again /wink.gif" style="vertical-align:middle" emoid=";)" border="0"
alt="wink.gif" /> since i make plugins for the steam-platform games, i mostly use databases for
storing data on like people's steamid and nickname for frequent visitors or banned people all
the other hosts i visited never allowed external access to the database i wonder if it's allowed
here but i wouldn't want to make the database server crash, since the database i would use
would get a lot of traffic every time a player joins a server or a ban happens with the global c...
I Cannot Connect To Mysql
- Can't connect to database (1)
I am trying to install an excellent mailing list program called poMMo - written in PHP. I keep
getting the below message and am not sure how to fix it. Connected to database server but could not
select database: "jeldi_pommo". jeldi_pommo is the name of my database. It works. I've checked
in phpMyAdmin through cPanel. It says it's connected to the MySQL server, so it cant be
user/pass issues. If anyone has any ideas, they would be much appreciated. I'm genuinely
stumped!...
Mysql Hostname?
- where can i get it (4)
Hey, im looking at a php script to connect to mySQL - it requires the password, username and
hostname to connect to the database. Im now looking at it in a very perplexed way. Ive looked on
cpanel but I can't see anything like this anywhere. Where can I find this information? If this
is nothing to do with you at all I'm very sorry for wasting your time.... Please be gentle, im
only a n00b /laugh.gif' border='0' style='vertical-align:middle' alt='laugh.gif' /> Thanks
very much guys You do great work, keep it up!...
Login Bug
- Keeps asking me to input a password (6)
I do not know if any of you have occurred this problem while trying to login to Trap17, but I did. I
go through the normal login steps, entering the username and password before clicking the submit
button, and expecting to be logged in into the forum. But it always brings me to the error page,
prompting me to key in my password, but my password is already in the password field. Although this
is a minor glitch, but it is getting kinda irritating especially since I always login using my
company's computer....
Fantastico Difficulties
- Mysql or fantastico problems ??? (1)
Yes, even frantastico ain't working and my AMFR forum hosting system is down. Please get it
fixed!...
Cpanel Login
- (2)
i just got approved this morning and i cant login.....i logged in earlier but now its saying that
the password is wrong and im 99 percent positive that its right....please help!...
Why Do I Always Have Problems.
- (2)
I've been posting and p[osting so that I could get 30 credits and requiest for a free Web
Hosting Account and now when I clikc the link that Buffalohelp sent me and after he approved of my
request I am now having problems in Xisto. It keeps telling me that my Username and Password are
invalid. can anybody tell me what I'm doing wrong???...
Which Mysql Version Does Trap17 Offer?
- Please clarify this for me (4)
I am trying to set up something that requires a Mysql database. I have made the account and user for
it and everything is OK, I just need to know what MySQL database type Trap17 offers to be able to
continue. I can select MySQL types between: 1. MySQL 3.x 2. MySQL 4.x/5.x Please help verify which
of these two Trap17 hosting package #2 offers /wink.gif" style="vertical-align:middle" emoid=";)"
border="0" alt="wink.gif" /> James...
Mysql Help Needed
- (2)
Right, where do I start... I have a phpbb forum, which is ok but doesnt give me the scope for
expansion which I need, so I have switched over to phpnuke (which has phpbb integrated anyway). My
problem is this - how do I transfer all the member details from the phpbb forum to the phpnuke
database? I'd really rather not have to ask everyone to rejoin if it can be helped, & I guess
there must be some clever way of using the mysql database to sort it out. I'll be the first to
admit i'm pretty clueless when it comes to the finer workings of mysql databases, so ...
Cpanel Login
- Some help here? (3)
I created a hosting account sometime this afternoon. I was able to go in and look around the cpanel,
but I didn't do anything. However, a few hours later, I was unable to login. The ftp login using
cmd was fine but the cpanel login at www.trap17.com/cpanel failed. I wasted 10 credits changing the
password. Please enlighten me. I apologize for using File-> save on the hosting account create
page. It didn't manage to save my account info. Where can I get them again?...
Urgent-admin Help Requested******
- Cpanel malfunction-& WEBSITE PROBLEMS (6)
Admin, Have posted a PM 4X today for "Opaque" - each time Cpanel has refused to log my message in
the "Sent" folder. Tried replying to the the previous message from Opaque & tried composing a new
message to him- >> same result - NO MESSAGE SENT!! after clicking the send button. Please
advise as this message string is concerning getting my website functional after ftp upload. -IS
URGENT !! Thanks RGPHNX...
Mysql And Free Hosting
- (8)
with the free hosting can I have a MySQL database and run PHP for a forum...
Mysql Only
- (2)
Would I be allowed to use my hosting account for MySQL only (no site)?...
Looking For Free Hosting With Mysql, Php And More
- I need help!!!! (4)
I am trying to find a website hosting server which is totally free with mysql and php and ahs alot
of megabyte storage If any one can help me please email me at ichhabezwei@hotmail.com...
Auto Login To Trap17 Forum
- without signing in (4)
everytime i come to this forum i have to log back in why is this? it cant be a problem on my end
because i goto several other Invision Boards and i never have to keep logging in on those ones.
Please be specific with topic title and do not leave description empty. Moving from General Talk to
Support. ...
My Forum Registration Problem?
- Hmmmmmmmmm.... (9)
I have no idea why but people cant register to my forums. on my website here:
http://finalchapter.trap17.com/index.htm (clikc forums). Does anyone have any clue why it is doing
this? Thanks. Topic title changed. ...
Trap17.com Mysql Databases
- Addresses, inquiry (2)
What is the SQL host address for trap17.com? example, google's could be db1.google.com. I am
looking for that address for trap17.com. Thanks, htdefiant...
Trap17 Problems (down)
- Trap17 Problems (down) (6)
Has anyone noticed that trap17.com seems to be down a lot or not enough bandwidth? I was just
posting a long comment in anther section and clicked post.. well guess what it said host not
found.. then i hit back and my WHOLE post was gone. Not even my credits went up. There have
numerous times I tried to access trap17 and get host not found. Whats the deal with this place.
You need to increase your bandwidth. This has become unreliable and I'm ready to start looking
elsewhere unless the problem can be corrected Anyone else see the same problems?...
Looking for login, registration, mysql, problems, session, terminates, quickly
|
|
Searching Video's for login, registration, mysql, problems, session, terminates, quickly
|
advertisement
|
|