Jump to content

Archived

This topic is now archived and is closed to further replies.

Greaser9780

NOOB ?

Recommended Posts

Not if you havnt implemented custom session save handlers.
Read the PHP manual for more information on sessions.

Share this post


Link to post
Share on other sites
[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.

Share this post


Link to post
Share on other sites
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 />";

?>

Share this post


Link to post
Share on other sites
<?
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

Share this post


Link to post
Share on other sites
You have to define the username with a login script or something somehow, or it will be blank..

Maybe I can throw something together.

Share this post


Link to post
Share on other sites
[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?

Share this post


Link to post
Share on other sites
Another noob ? How do I define it then. I understand what you are saying but I have about 3-4 comands memerised.

Share this post


Link to post
Share on other sites
Here is a way to define it by typing your username in the box hitting submit:
(I said I was putting it together - )

[code]<?php
session_start();
$_SESSION["username"] = $_POST["username"];
{
echo "Welcome ". $_SESSION['username'] ." ";
}
?>

<form action="" method="POST">
<input type="text" name="username">
<input type="submit">
</form>[/code]

Share this post


Link to post
Share on other sites
[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]

Share this post


Link to post
Share on other sites
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. :) :) :)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.