Jump to content


Photo

session ids


  • Please log in to reply
4 replies to this topic

#1 bonzie

bonzie
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 20 June 2006 - 11:28 AM

Hi all,

Because giving through session variables don't work I would like to try session ids.

This is my idea
1. Login page with form to fill out username and password (no session_start(); ), directed to home.php
2. home.php:
<?php
session_start();
$username = $HTTP_POST_VARS['userName']; // this is correct!
$id=$username;
?>

<html>
<body>
<a href="recomm.php?<?php echo $id?>">Link</a>

3. recomm.php
session_start();
here I need the username of the user logged in. So I thought that I could use the variable $id...
However, this variable is now empty.

What do I do wrong?

#2 joecooper

joecooper
  • Members
  • PipPipPip
  • Advanced Member
  • 358 posts

Posted 20 June 2006 - 11:33 AM

to use sessions. all pages that are using them needs to have

session_start(); at the top of them

$_SESSION[''] is the varible used

so to set the session varible for username use

$_SESSION['username'] = $username;

then across the other pages, you can bring up $_SESSION['username']

and it will return what ever the $username varible was set as in the first page

<?php
session_start();
$username = $HTTP_POST_VARS['userName']; // this is correct!
$id=$username;
?>

change to this

<?php
session_start();
$username = $HTTP_POST_VARS['userName']; // this is correct!
$id=$username;
$_SESSION['username'] = $username;
?>

this will set the session varible

and on the other page, use this to echo the username

echo "Welcome, {$_SESSION['username']}.";
Signature:
[/a]
[a href="http://www.planet-so...=1999&lngWId=8" target="_blank"]EzLogin 1.0[/a]
[a href="http://www.essexracers.com" target="_blank"]Essexracers.com[/a]
Msn Messenger: joe@joeyjoe.co.uk

#3 bonzie

bonzie
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 20 June 2006 - 11:53 AM

ok

I tried this, however I don't get the username with the echo statement...

Anyone an idea?

[!--quoteo(post=385966:date=Jun 20 2006, 01:33 PM:name=joecooper)--][div class=\'quotetop\']QUOTE(joecooper @ Jun 20 2006, 01:33 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
to use sessions. all pages that are using them needs to have

session_start(); at the top of them

$_SESSION[''] is the varible used

so to set the session varible for username use

$_SESSION['username'] = $username;

then across the other pages, you can bring up $_SESSION['username']

and it will return what ever the $username varible was set as in the first page

<?php
session_start();
$username = $HTTP_POST_VARS['userName']; // this is correct!
$id=$username;
?>

change to this

<?php
session_start();
$username = $HTTP_POST_VARS['userName']; // this is correct!
$id=$username;
$_SESSION['username'] = $username;
?>

this will set the session varible

and on the other page, use this to echo the username

echo "Welcome, {$_SESSION['username']}.";
[/quote]


#4 joecooper

joecooper
  • Members
  • PipPipPip
  • Advanced Member
  • 358 posts

Posted 20 June 2006 - 11:56 AM

$uname = $_SESSION['username'];
echo "Welcome, $uname .";


try that instead
Signature:
[/a]
[a href="http://www.planet-so...=1999&lngWId=8" target="_blank"]EzLogin 1.0[/a]
[a href="http://www.essexracers.com" target="_blank"]Essexracers.com[/a]
Msn Messenger: joe@joeyjoe.co.uk

#5 bonzie

bonzie
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 20 June 2006 - 12:06 PM

That doesn't work neither :s

[!--quoteo(post=385977:date=Jun 20 2006, 01:56 PM:name=joecooper)--][div class=\'quotetop\']QUOTE(joecooper @ Jun 20 2006, 01:56 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
$uname = $_SESSION['username'];
echo "Welcome, $uname .";
try that instead
[/quote]





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users