bonzie Posted June 20, 2006 Share Posted June 20, 2006 Hi all,Because giving through session variables don't work I would like to try session ids.This is my idea1. Login page with form to fill out username and password (no session_start(); ), directed to home.php2. home.php:[code]<?phpsession_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 https://forums.phpfreaks.com/topic/12456-session-ids/ Share on other sites More sharing options...
joecooper Posted June 20, 2006 Share Posted June 20, 2006 to use sessions. all pages that are using them needs to havesession_start(); at the top of them$_SESSION[''] is the varible usedso 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]<?phpsession_start();$username = $HTTP_POST_VARS['userName']; // this is correct!$id=$username;?>[/code]change to this[code]<?phpsession_start();$username = $HTTP_POST_VARS['userName']; // this is correct!$id=$username;$_SESSION['username'] = $username;?>[/code]this will set the session varibleand on the other page, use this to echo the usernameecho "Welcome, {$_SESSION['username']}."; Link to comment https://forums.phpfreaks.com/topic/12456-session-ids/#findComment-47619 Share on other sites More sharing options...
bonzie Posted June 20, 2006 Author Share Posted June 20, 2006 okI 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 havesession_start(); at the top of them$_SESSION[''] is the varible usedso 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]<?phpsession_start();$username = $HTTP_POST_VARS['userName']; // this is correct!$id=$username;?>[/code]change to this[code]<?phpsession_start();$username = $HTTP_POST_VARS['userName']; // this is correct!$id=$username;$_SESSION['username'] = $username;?>[/code]this will set the session varibleand on the other page, use this to echo the usernameecho "Welcome, {$_SESSION['username']}.";[/quote] Link to comment https://forums.phpfreaks.com/topic/12456-session-ids/#findComment-47625 Share on other sites More sharing options...
joecooper Posted June 20, 2006 Share Posted June 20, 2006 $uname = $_SESSION['username'];echo "Welcome, $uname .";try that instead Link to comment https://forums.phpfreaks.com/topic/12456-session-ids/#findComment-47627 Share on other sites More sharing options...
bonzie Posted June 20, 2006 Author Share Posted June 20, 2006 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 https://forums.phpfreaks.com/topic/12456-session-ids/#findComment-47629 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.