Jump to content


Photo

problem with sessions


  • Please log in to reply
7 replies to this topic

#1 bonzie

bonzie
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 20 June 2006 - 07:49 AM

Hi all,

I try to create a small website with a login, however I don't get the sessions work.
My login is (index.php): (in HTML)
<p><form method=post action="home.php>">
  <table cellpadding="2" cellspacing="2" align="center" border="0">
    <tr><td colspan="2" align="center">Please Log in here:</td>
    </tr>
    <tr><td align="right"class="logintext">Username:</td>
           <td><input size="15" maxlength="10" name="userName" type="text"/></td>
    </tr>
    <tr><td align="right" class="logintext">Password:</td>
           <td><input size="15" maxlength="10" name="userPassword" type="password"/></td>
    </tr>
    <tr align="center"><td colspan="2" align="center"><input value="login" name="action" type="hidden"/><input value="Log in" name="submit" type="submit"/>                               </td>
    </tr>
  </table>

Now I want to create a session when people login, because I want to be able to identify people (via their username) when they browse further.
I have tried several things but nothing worked. Could you help me?
Thnx

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 20 June 2006 - 09:00 AM

There are tons of tutorials out there explaining these stuff.
Read, and you still cant figure out why some script doesnt work post it here and we'll try to fix it [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 bonzie

bonzie
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 20 June 2006 - 09:19 AM

I read already some stuff on sessions, however probably I do something wrong.

From my login page people are directed to index2.php.
On this page I have
<?php
//start session
session_start();
$username = $HTTP_POST_VARS['userName'];
$password = $HTTP_POST_VARS['userPassword'];
$_SESSION['user']=$username;
...
?>
Then in the body of my document (HTML) I have a link:
<body>
<a class="menu" href="recomm.php">Get Recommendation</a>
</body>
I tried it like this, on the page "recomm.php" the session variable (_SESSION['user'])was empty...
What do I wrong?
Is it better to use session_id? And if yes how do I have to integrate this in the URL?

thnx

[!--quoteo(post=385906:date=Jun 20 2006, 11:00 AM:name=Orio)--][div class=\'quotetop\']QUOTE(Orio @ Jun 20 2006, 11:00 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
There are tons of tutorials out there explaining these stuff.
Read, and you still cant figure out why some script doesnt work post it here and we'll try to fix it [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]

Orio.
[/quote]


#4 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 20 June 2006 - 09:24 AM

Do you start the sessions on recomm.php? It has to have session_start() in the begining so it can fetch the vars set on previous pages.

Orio.
Think you're smarty?

(Gone until 20 to November)

#5 bonzie

bonzie
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 20 June 2006 - 09:32 AM

in recomm.php I have
<?php

//start session
session_start();
$username=$_SESSION['user'];
When I do
echo $username;
I don't get anything.

[!--quoteo(post=385916:date=Jun 20 2006, 11:24 AM:name=Orio)--][div class=\'quotetop\']QUOTE(Orio @ Jun 20 2006, 11:24 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Do you start the sessions on recomm.php? It has to have session_start() in the begining so it can fetch the vars set on previous pages.

Orio.
[/quote]


#6 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 20 June 2006 - 09:36 AM

Hmmm
Everything seems fine, maybe it's the problem with the form?
Your code says:
$username = $HTTP_POST_VARS['userName'];
$password = $HTTP_POST_VARS['userPassword'];

Are you sure that in the login form the fields are called userName and userPassword ? And the method is post?

Orio.

EDIT- I just saw you posted the form as well, and it's ok... I have no idea whats wrong!
Think you're smarty?

(Gone until 20 to November)

#7 bonzie

bonzie
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 20 June 2006 - 09:46 AM

is it maybe better to use session ids?

in the index2.php I would then put
<?php
//start session
session_start();
$id=session_id();
$username = $HTTP_POST_VARS['userName'];
$password = $HTTP_POST_VARS['userPassword'];
$_SESSION['user']=$username;
$id=$username; // because I want the id to be the username
...
?>

Is this correct?
And how do I integrate then the id in the URL?

thnx
[!--quoteo(post=385921:date=Jun 20 2006, 11:36 AM:name=Orio)--][div class=\'quotetop\']QUOTE(Orio @ Jun 20 2006, 11:36 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Hmmm
Everything seems fine, maybe it's the problem with the form?
Your code says:
$username = $HTTP_POST_VARS['userName'];
$password = $HTTP_POST_VARS['userPassword'];

Are you sure that in the login form the fields are called userName and userPassword ? And the method is post?

Orio.

EDIT- I just saw you posted the form as well, and it's ok... I have no idea whats wrong!
[/quote]


#8 bonzie

bonzie
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 20 June 2006 - 10:11 AM

I tried with an easy example:
login form:
<p><form method=post action="home.php>">
  <table cellpadding="2" cellspacing="2" align="center" border="0">
    <tr><td colspan="2" align="center">Please Log in here:</td>
    </tr>
    <tr><td align="right"class="logintext">Username:</td>
           <td><input size="15" maxlength="10" name="userName" type="text"/></td>
    </tr>
    <tr><td align="right" class="logintext">Password:</td>
           <td><input size="15" maxlength="10" name="userPassword" type="password"/></td>
    </tr>
    <tr align="center"><td colspan="2" align="center"><input value="login" name="action" type="hidden"/><input value="Log in" name="submit" type="submit"/>                               </td>
    </tr>
  </table>


Now in home.php i put:

<?php
session_start();
$id=session_id();
$username = $HTTP_POST_VARS['userName'];
?>

In HTML body
<a href="home2.php?<?php $id ?>"> link</a>

The id in the URL doesn't work. And as i am a beginner I don't see why.
Can you help?

[!--quoteo(post=385924:date=Jun 20 2006, 11:46 AM:name=bonzie)--][div class=\'quotetop\']QUOTE(bonzie @ Jun 20 2006, 11:46 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
is it maybe better to use session ids?

in the index2.php I would then put
<?php
//start session
session_start();
$id=session_id();
$username = $HTTP_POST_VARS['userName'];
$password = $HTTP_POST_VARS['userPassword'];
$_SESSION['user']=$username;
$id=$username; // because I want the id to be the username
...
?>

Is this correct?
And how do I integrate then the id in the URL?

thnx
[/quote]





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users