Dr Ben Warne Posted December 4, 2006 Share Posted December 4, 2006 Having bought several books on the matter, i am still trying to tacle the a simple problem, and literature i have found is more complex than i need.I an simply looking for a code that can create a session id and associate it with a name, returning a screen of Welcome ......... your session id is......... and have that session id saved in a text file, any ideas?Thank youBen Link to comment https://forums.phpfreaks.com/topic/29391-session-id/ Share on other sites More sharing options...
trq Posted December 4, 2006 Share Posted December 4, 2006 Search for tutorials on a login system. Thats the only way your going to get a session id to associate with a name. Link to comment https://forums.phpfreaks.com/topic/29391-session-id/#findComment-134788 Share on other sites More sharing options...
Dr Ben Warne Posted December 4, 2006 Author Share Posted December 4, 2006 [quote author=thorpe link=topic=117290.msg478381#msg478381 date=1165239994]Search for tutorials on a login system. Thats the only way your going to get a session id to associate with a name.[/quote]I have tried, but am still unable to find any of relevance Link to comment https://forums.phpfreaks.com/topic/29391-session-id/#findComment-134796 Share on other sites More sharing options...
radalin Posted December 4, 2006 Share Posted December 4, 2006 set a cookie on the client side like $_COOKIE['session_id'] or use a server side cookie (also called as session) $_SESSION['session_id']. Until you use session_unregister() function or the user do not close the browser $_SESSION is kept, if you use cookies then it will last till they expire. Link to comment https://forums.phpfreaks.com/topic/29391-session-id/#findComment-134804 Share on other sites More sharing options...
Dr Ben Warne Posted December 4, 2006 Author Share Posted December 4, 2006 [quote author=radalin link=topic=117290.msg478397#msg478397 date=1165241372]set a cookie on the client side like $_COOKIE['session_id'] or use a server side cookie (also called as session) $_SESSION['session_id']. Until you use session_unregister() function or the user do not close the browser $_SESSION is kept, if you use cookies then it will last till they expire.[/quote]But how do i display all the info i want? Link to comment https://forums.phpfreaks.com/topic/29391-session-id/#findComment-134807 Share on other sites More sharing options...
trq Posted December 4, 2006 Share Posted December 4, 2006 Really.. do you want us to write yet another tutorial especially for you? Link to comment https://forums.phpfreaks.com/topic/29391-session-id/#findComment-134853 Share on other sites More sharing options...
Dr Ben Warne Posted December 4, 2006 Author Share Posted December 4, 2006 [quote author=thorpe link=topic=117290.msg478446#msg478446 date=1165243998]Really.. do you want us to write yet another tutorial especially for you?[/quote]A link might be nice :) Link to comment https://forums.phpfreaks.com/topic/29391-session-id/#findComment-134859 Share on other sites More sharing options...
trq Posted December 4, 2006 Share Posted December 4, 2006 I havent done a tutorial in a long while so Im sorry I don't have a link handy. Goggle however produces 19 million + hits on the subject.In its simplest terms.[code]<?php session_start(); $_SESSION['uname'] = "thorpe"; echo "Welcome {$_SESSION['uname']}, your session id is ". session_id();?>[/code] Link to comment https://forums.phpfreaks.com/topic/29391-session-id/#findComment-134863 Share on other sites More sharing options...
Dr Ben Warne Posted December 4, 2006 Author Share Posted December 4, 2006 [quote author=thorpe link=topic=117290.msg478456#msg478456 date=1165244911]I havent done a tutorial in several years so Im sorry I don't have a link handy. Goggle however produces 19 million + hits on the subject.In its simplest terms.[code]<?php session_start(); $_SESSION['uname'] = "thorpe"; echo "Welcome {$_SESSION['uname']}, your session id is ". session_id();?>[/code][/quote]How would the new user enter their details ie nickname etc for it to the create a session id associated to it? Would that then remember the name for the next log on if the cookie is still there? Link to comment https://forums.phpfreaks.com/topic/29391-session-id/#findComment-134866 Share on other sites More sharing options...
trq Posted December 4, 2006 Share Posted December 4, 2006 Maybe this will help.[code]<?php session_start(); if (!isset($_POST['submit'])) { echo "<form method='post'>"; echo " your name?<input type='text' name='uname'>"; echo " <input type='submit'>"; echo "</form>"; } else { $_SESSION['uname'] = $_POST['uname']; echo "Welcome {$_SESSION['uname']}, your session id is ". session_id(); }?>[/code]And no. Sessions only last the lifetime of a users visit. You will need to use cookies aswell if you want persistence. Link to comment https://forums.phpfreaks.com/topic/29391-session-id/#findComment-134870 Share on other sites More sharing options...
Dr Ben Warne Posted December 4, 2006 Author Share Posted December 4, 2006 [quote author=thorpe link=topic=117290.msg478463#msg478463 date=1165245485]Maybe this will help.[code]<?php session_start(); if (!isset($_POST['submit'])) { echo "<form method='post'>"; echo " your name?<input type='text' name='uname'>"; echo " <input type='submit'>"; echo "</form>"; } else { $_SESSION['uname'] = $_POST['uname']; echo "Welcome {$_SESSION['uname']}, your session id is ". session_id(); }?>[/code]And no. Sessions only last the lifetime of a users visit. You will need to use cookies aswell if you want persistence.[/quote]This code doesnt seem to do anything ??? Link to comment https://forums.phpfreaks.com/topic/29391-session-id/#findComment-134872 Share on other sites More sharing options...
trq Posted December 4, 2006 Share Posted December 4, 2006 Sorry, Im not at my server so can't test it. Looks OK to me though. Link to comment https://forums.phpfreaks.com/topic/29391-session-id/#findComment-134875 Share on other sites More sharing options...
HuggieBear Posted December 4, 2006 Share Posted December 4, 2006 The code's almost correct... The problem is that the submit button doesn't have a name...This should work.[code]<?php session_start(); if (!isset($_POST['submit'])) { echo "<form method='post'>"; echo " your name?<input type='text' name='uname'>"; echo " <input type='submit' name='submit'>"; echo "</form>"; } else { $_SESSION['uname'] = $_POST['uname']; echo "Welcome {$_SESSION['uname']}, your session id is ". session_id(); }?>[/code]RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/29391-session-id/#findComment-134934 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.