Jump to content

session ids


bonzie

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?
Link to comment
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']}.";
Link to comment
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]
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.