Greaser9780 Posted August 28, 2006 Share Posted August 28, 2006 Must I start a db connection in order to get a session to start? Quote Link to comment Share on other sites More sharing options...
spfoonnewb Posted August 28, 2006 Share Posted August 28, 2006 no. you may need session_start() Quote Link to comment Share on other sites More sharing options...
Joe Haley Posted August 28, 2006 Share Posted August 28, 2006 Not if you havnt implemented custom session save handlers.Read the PHP manual for more information on sessions. Quote Link to comment Share on other sites More sharing options...
Caesar Posted August 28, 2006 Share Posted August 28, 2006 [quote author=Greaser9780 link=topic=106005.msg423670#msg423670 date=1156806858]Must I start a db connection in order to get a session to start?[/quote]No. You do not need to utilize a database to make use of sessions or session variables. Quote Link to comment Share on other sites More sharing options...
Greaser9780 Posted August 28, 2006 Author Share Posted August 28, 2006 OK then I have a welcome message set to come up when my page loads. It is supposed to echo Welcome! and then display the username that was used to login. It only displays Welcome! and appears that the username is not being called. Here is the PHP part of the page:<?session_start();echo "Welcome ". $_SESSION['username'] ." <br /><br />"; ?> Quote Link to comment Share on other sites More sharing options...
spfoonnewb Posted August 28, 2006 Share Posted August 28, 2006 How was the username defined? Quote Link to comment Share on other sites More sharing options...
Greaser9780 Posted August 28, 2006 Author Share Posted August 28, 2006 <?session_start();echo "Welcome ". $_SESSION['username'] ." <br /><br />"; ?>I'm not sure what you mean. I have a very limited background in PHP and up till recently most was copy and paste then edit where I had to. This script worked before when it was called by an include message and this script was labeled welcome.php Quote Link to comment Share on other sites More sharing options...
spfoonnewb Posted August 28, 2006 Share Posted August 28, 2006 You have to define the username with a login script or something somehow, or it will be blank..Maybe I can throw something together. Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 28, 2006 Share Posted August 28, 2006 [quote author=spfoonnewb link=topic=106005.msg423678#msg423678 date=1156807303]How was the username defined?[/quote]Put another way, HOW did $_SESSION['username'] get given any value in the login process? Quote Link to comment Share on other sites More sharing options...
Greaser9780 Posted August 28, 2006 Author Share Posted August 28, 2006 Another noob ? How do I define it then. I understand what you are saying but I have about 3-4 comands memerised. Quote Link to comment Share on other sites More sharing options...
spfoonnewb Posted August 28, 2006 Share Posted August 28, 2006 Here is a way to define it by typing your username in the box hitting submit:(I said I was putting it together - )[code]<?phpsession_start();$_SESSION["username"] = $_POST["username"];{echo "Welcome ". $_SESSION['username'] ." ";}?><form action="" method="POST"><input type="text" name="username"><input type="submit"></form>[/code] Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 28, 2006 Share Posted August 28, 2006 [quote author=Greaser9780 link=topic=106005.msg423685#msg423685 date=1156807921]Another noob ? How do I define it then. I understand what you are saying but I have about 3-4 comands memerised.[/quote]Well, 'somewhere' in your login script the username is obtained. Suppose it was known as the variable $wombat. Then .... drum roll:[code]$_SESSION['username'] = $wombat;// save the username in a session variable[/code] Quote Link to comment Share on other sites More sharing options...
Greaser9780 Posted August 28, 2006 Author Share Posted August 28, 2006 Thank you andyB. Finally it worked I couldn't use $_POST['username'] because the form was already handled in my checkuser.php file. I looked up how it was defined in there and VOILA!! SUCCESS!!!Gosh you people are smart. Only my first week. Hard to learn it and build the site at the same time. Thank you for your cooperation. :) :) :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.