Greaser9780 Posted August 28, 2006 Share Posted August 28, 2006 Must I start a db connection in order to get a session to start? Link to comment https://forums.phpfreaks.com/topic/18956-noob/ Share on other sites More sharing options...
spfoonnewb Posted August 28, 2006 Share Posted August 28, 2006 no. you may need session_start() Link to comment https://forums.phpfreaks.com/topic/18956-noob/#findComment-81924 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. Link to comment https://forums.phpfreaks.com/topic/18956-noob/#findComment-81925 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. Link to comment https://forums.phpfreaks.com/topic/18956-noob/#findComment-81926 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 />"; ?> Link to comment https://forums.phpfreaks.com/topic/18956-noob/#findComment-81930 Share on other sites More sharing options...
spfoonnewb Posted August 28, 2006 Share Posted August 28, 2006 How was the username defined? Link to comment https://forums.phpfreaks.com/topic/18956-noob/#findComment-81931 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 Link to comment https://forums.phpfreaks.com/topic/18956-noob/#findComment-81932 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. Link to comment https://forums.phpfreaks.com/topic/18956-noob/#findComment-81933 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? Link to comment https://forums.phpfreaks.com/topic/18956-noob/#findComment-81935 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. Link to comment https://forums.phpfreaks.com/topic/18956-noob/#findComment-81938 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] Link to comment https://forums.phpfreaks.com/topic/18956-noob/#findComment-81939 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] Link to comment https://forums.phpfreaks.com/topic/18956-noob/#findComment-81941 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. :) :) :) Link to comment https://forums.phpfreaks.com/topic/18956-noob/#findComment-81947 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.