Jump to content

Archived

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

bonzie

session ids

Recommended Posts

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:
[code]
<?php
session_start();
$username = $HTTP_POST_VARS['userName']; // this is correct!
$id=$username;
?>

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

3. recomm.php
[code]
session_start();
[/code]
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?

Share this post


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

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

change to this

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

this will set the session varible

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

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

Share this post


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

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

change to this

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

this will set the session varible

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

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

Share this post


Link to post
Share on other sites
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) [snapback]385977[/snapback][/div][div class=\'quotemain\'][!--quotec--]
$uname = $_SESSION['username'];
echo "Welcome, $uname .";
try that instead
[/quote]

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.