Jump to content


Photo

NOOB ?


  • Please log in to reply
12 replies to this topic

#1 Greaser9780

Greaser9780
  • Members
  • PipPipPip
  • Advanced Member
  • 326 posts

Posted 28 August 2006 - 11:14 PM

Must I start a db connection in order to get a session to start?

#2 spfoonnewb

spfoonnewb
  • Members
  • PipPipPip
  • Advanced Member
  • 276 posts

Posted 28 August 2006 - 11:15 PM

no. you may need session_start()

#3 Joe Haley

Joe Haley
  • Members
  • PipPipPip
  • Advanced Member
  • 103 posts
  • LocationCanada, eh?

Posted 28 August 2006 - 11:15 PM

Not if you havnt implemented custom session save handlers.
Read the PHP manual for more information on sessions.
Give a man a fish; you have fed him for today.  Teach a man to fish; and you have fed him for a lifetime
Don't teach men to program. Teach them to fish.

Please, try the RTFM solution before asking for help:
http://php.net/manual/en/index.php

#4 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 28 August 2006 - 11:15 PM

Must I start a db connection in order to get a session to start?


No. You do not need to utilize a database to make use of sessions or session variables.
PHP Ninja

#5 Greaser9780

Greaser9780
  • Members
  • PipPipPip
  • Advanced Member
  • 326 posts

Posted 28 August 2006 - 11:20 PM

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 />";

?>

#6 spfoonnewb

spfoonnewb
  • Members
  • PipPipPip
  • Advanced Member
  • 276 posts

Posted 28 August 2006 - 11:21 PM

How was the username defined?

#7 Greaser9780

Greaser9780
  • Members
  • PipPipPip
  • Advanced Member
  • 326 posts

Posted 28 August 2006 - 11:22 PM

<?
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

#8 spfoonnewb

spfoonnewb
  • Members
  • PipPipPip
  • Advanced Member
  • 276 posts

Posted 28 August 2006 - 11:27 PM

You have to define the username with a login script or something somehow, or it will be blank..

Maybe I can throw something together.

#9 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 28 August 2006 - 11:28 PM

How was the username defined?


Put another way, HOW did $_SESSION['username'] get given any value in the login process?
Legend has it that reading the manual never killed anyone.
My site

#10 Greaser9780

Greaser9780
  • Members
  • PipPipPip
  • Advanced Member
  • 326 posts

Posted 28 August 2006 - 11:32 PM

Another noob ? How do I define it then. I understand what you are saying but I have about 3-4 comands memerised.

#11 spfoonnewb

spfoonnewb
  • Members
  • PipPipPip
  • Advanced Member
  • 276 posts

Posted 28 August 2006 - 11:33 PM

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

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

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


#12 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 28 August 2006 - 11:36 PM

Another noob ? How do I define it then. I understand what you are saying but I have about 3-4 comands memerised.


Well, 'somewhere' in your login script the username is obtained.  Suppose it was known as the variable $wombat.  Then .... drum roll:

$_SESSION['username'] = $wombat;// save the username in a session variable

Legend has it that reading the manual never killed anyone.
My site

#13 Greaser9780

Greaser9780
  • Members
  • PipPipPip
  • Advanced Member
  • 326 posts

Posted 28 August 2006 - 11:47 PM

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. :) :) :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users