Jump to content

Session Id


Dr Ben Warne

Recommended Posts

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 you

Ben
Link to comment
Share on other sites

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

[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
Share on other sites

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

[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
Share on other sites

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

[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
Share on other sites

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]

Regards
Huggie
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.