Closed Thread Icon

Topic awaiting preservation: Sessions (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12776" title="Pages that link to Topic awaiting preservation: Sessions (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Sessions <span class="small">(Page 1 of 1)</span>\

 
Trigger
Paranoid (IV) Inmate

From:
Insane since: Jun 2002

posted posted 06-07-2003 18:53

OK im makeing a website in PHP & MYSQL for add on to a harry potter comunity my girlfriend runs, the place was made in perl by her brother, you may of seen me dropping the links and now then.. anyway
The site is made in php & mysql and needless to say good ol brother dosent know a thing about it,

anyone i've been musing over sessions,cookies and BASIC HTTP authentication methods and from what I've read sessions would be best, because I want ot extract certian data from the user table like there name the department there in, email adress privalge level and the such and use it site wide,

unfortuantly the articles i've read on sessions and how to use them have been vauge or very un indepth
so if anyone can suggest a E/book on the topic or a link to a relivant site , that is a bit more indepth on sessiosn than most places i've seen the help would be greatly appreciated
I've checked the FAQ and I've RTFM


Trigger -

jive
Paranoid (IV) Inmate

From: Greenville, SC, USA
Insane since: Jan 2002

posted posted 06-07-2003 21:39

try Sitepoint They've got some good articles. I'm reading a great book by sitepoints kevin yank : build your own database driven website with php and mysql. So far it's been easy to follow and I've been able to pick up php extremly fast because of it.



Trigger
Paranoid (IV) Inmate

From:
Insane since: Jun 2002

posted posted 06-07-2003 21:41

Yerer I've read Sitepoints article on that, but it dosent explain how I get my data from a database and into the session and I cant quite work it out myself

I've tried
loading everything into a loop and assining ach varaible to a Session_register('varname'); but it dosent take,
and im not too sure if I have to od anything else to 'send' the cookie with the SessionID either..


Thanks
Trigger

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 06-08-2003 00:03

Trigger

If you show what you've tried code wise it will be easier to point out suggestions or help you understand why it's not working.

-Butcher-

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 06-08-2003 10:29

well, let's say you have started your session with
session_start(); //before all other output!

and you have retrieved variable data from your database that's currently in $foo...
then you can do
$_SESSION['foo'] = $foo;

and retrieve it on subsequent pages with
if isset($_SESSION['foo'])
{
print "Your foo is ". $_SESSION['foo'];
}

Trigger
Paranoid (IV) Inmate

From:
Insane since: Jun 2002

posted posted 06-08-2003 10:40

Butcher im yet to actulay code anything regarding it because i cant quite get my head around it .. .

so far all's I've got is a script that checks if PHPSESSID is set and if so show something else, and if not then show the login page -- but that dosent seem to work because PHPSESSID seems to be set when the session_start() is acitvated which is in my header file so thats every page..

so prehaps I should set a varaible when login is correct such as "logged in" and then when they log out, unset it or just destoy the session,

so I'd do my while statement

while $foo = mysql_fetch_array($result){

// id
$_SESSION['id'] = $foo[0];
//username
$_SESSION['username'] = $foo[1];


etc etc etc ?

sukerman
Nervous Wreck (II) Inmate

From: BATH, UK
Insane since: Jun 2003

posted posted 06-23-2003 16:32

Don't worry about session id's.

All you need to know is that $_SESSION will be a variable shared across
all pages that begin with the <? session_start(); ?>.

This line must appear before your page outputs anything else.

$_SESSION will behave like an array variable.

set stuff in the session like this:

$_SESSION['name'] = "Jack";
$_SESSION['age'] = "18";

retrieve stuff like this:

$name = $_SESSION['name'];
$age = $_SESSION['name'];

print "Hello $name, your age is $age";

For viewing the contents of arrays use the
print_r function.

e.g, print_r($_SESSION)

... will display a readable version of the
contents of your session array.

As for :

while $foo = mysql_fetch_array($result){

// id
$_SESSION['id'] = $foo[0];
//username
$_SESSION['username'] = $foo[1];

This is going to overwrite the variable 'id' for
each row in the loop. What I would do is:

$users = "";
while $foo = mysql_fetch_array($result){
$_SESSION['id'] .= $foo[0].":";
$_SESSION['username'] = $foo[1].":";
}

This will result in

$_SESSION['id'] = "1:2:3:5";
$_SESSION['username'] = "Jack:John:Bill:Wendy";

You can then extract them into an array with
$users = explode(":",$_SESSION['username']);
// show users
foreach ($users as $user){
print "Hello $user";
}

You are going to need to get your head around
using arrays and arrays of arrays really to keep
things tidy.

Hope this helps,

J.

[This message has been edited by sukerman (edited 06-23-2003).]

[This message has been edited by sukerman (edited 06-23-2003).]

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 06-23-2003 17:06

just wondering, sukerman (welcome, btw),
but why wouldn't you just store the ids and usernames in an array allright, without having to explode afterwards?

$_SESSION['ids'] = array();
while ($aRow = mysql_fetch_row($result))
{
$_SESSION['ids'][] = $aRow['id'];
}

« BackwardsOnwards »

Show Forum Drop Down Menu