Jump to content

[SOLVED] Experiments on Session!


oceans

Recommended Posts

Dear Friends,

 

I asked and did a lot of experiments on sessions.

 

The following is what I found:

 

When two or more client programs are open from the SAME computer, there are NO multiple session files but only one, thus the server uses the same data set from a single session file for all the client programs from the SAME computer, this is disaster!

 

How can I overcome, please?

 

I use the following:

 

ob_start();
session_start();
$NumberOfSessionVariables=4;
for ($i=1; $i<=$NumberOfSessionVariables; $i++)
{
$_SESSION['14ForView'.$i]=0;
}

 

I also noted, my WAMP server does not removes the session files after the client has left.

 

One of our fiends has suggested me:

 

http://sg2.php.net/session_destroy

 

I think,if I were to permanently set the time out for a session in the ini file, it should be far better, can any one teach me what line should I edit in the ini file.

 

Thanks.

 

Link to comment
https://forums.phpfreaks.com/topic/54228-solved-experiments-on-session/
Share on other sites

Like this

<?php

$example = "3242sfs3245242"; // This is the session id which is generated when you you first time start the session

session_id($ezample);

session_start();

 

?>

 

In this case you need to pass session id in each page when you redirect either in query string or through post .

Do you mean I should have this

ob_start();
$example = "3242sfs3245242"; // This is the session id which is generated when you you first time start the session
session_id($example);
session_start();
$NumberOfSessionVariables=4;
for ($i=1; $i<=$NumberOfSessionVariables; $i++)
{
$_SESSION['14ForView'.$i]=0;
}

 

how do i call the session is it like this

 

$value=$_SESSION['14ForView1'];

 

or some thing else?

 

 

I do not mean to set session_id in session variable

 

It may be like this

 

http://www.domain.com/index.php?session_id=s3f34er345ff3453f34534

---------------------------------------------------------------------

 

Now in index.php file set

 

<?php

session_id($_GET['session_id']);

session_start();

..............

.............

..............

?>

in this case you should have session id all time.

Dear Jitesh,

 

I am confused, please bare with me.

 

this is what i have in my index.php

 

<?php
header('location:112/Home.php');
?>

 

that is all.

 

 

you want me to do this

 


<?php
ob_start();
header('location:112/Home.php');
session_id($_GET['session_id']);
session_start();
?>


 

am I right

 

well on the other pages I do not do any thing, if I start new variables for the respective pages, i leave them as


ob_start();
session_start();
$NumberOfSessionVariables=4;
for ($i=1; $i<=$NumberOfSessionVariables; $i++)
{
$_SESSION['14ForView'.$i]=0;
}

 

Will I be ok?

<?php

ob_start();

header('location:112/Home.php?session_id=$_GET['session_id']);

?>

-------------------------------------------------------------

 

Other page

 

 

ob_start();

-----------------------------

session_id($_GET['session_id']);  // You need to set session id before session start each time. (which is created when you have first time start session)

-----------------------------

session_start();

$NumberOfSessionVariables=4;

for ($i=1; $i<=$NumberOfSessionVariables; $i++)

{

$_SESSION['14ForView'.$i]=0;

}

 

in simple word the flow is with two line

sessiion_id('.....');

session_start();

Dear Jitesh,

 

I think there could be a typo in your

 

 

<?php

ob_start();

header('location:112/Home.php?session_id=$_GET['session_id']);

?>

 

I get the following error

"

Parse error: syntax error, unexpected T_STRING in C:\wamp\www\Index.php on line 3

"

 

by the way even if we were to do your method, am I right to say the id number will be the same always for all computers, i may be wrong. correct me.

ok index went through

 

now my page

 

i get the following error

"

Warning: session_start() [function.session-start]: The session id contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in C:\wamp\www\113\1401View.php on line 5

"

 

line 5 refers to "session_start();"

 

<?php

ob_start();

session_start();   // when first time set session

$this_is_set_session_id = session_id();

header('location:112/Home.php?session_id='.$this_is_set_session_id);

?>

-------------------------------------------------------------

 

 

Home.php

ob_start();

-----------------------------

// If session is set then use previous set session by old session id otherwise start new session

$this_is_set_session_id = isset($_GET['session_id'])?$_GET['session_id']:"";

session_id($this_is_set_session_id);

-----------------------------

session_start();

$NumberOfSessionVariables=4;

for ($i=1; $i<=$NumberOfSessionVariables; $i++)

{

   $_SESSION['14ForView'.$i]=0;

}

Friend, what I noted,

when the index pages starts i get one file,

 

when the home page starts i get one more file.

 

the error on the home page

"

 

Warning: session_start() [function.session-start]: The session id contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in C:\wamp\www\113\1401View.php on line 7

 

"

line 7 refers to "session_start();"

 

Thanks for being with me friend.

I will let you know the full story.

 

I have about 50 of pages grouped into 5 catagory.

 

For each catagory, I will get user name and other info independent to other catagory, keep them alive in in sessions till the user goes to the end of the catagory, and i will unset the sessions at the last page.

 

Thus I have 5 sets of sesions variables.

 

This is what i do every time I need to start a catagory, i will do the following:

ob_start();

session_start();

$NumberOfSessionVariables=4;

for ($i=1; $i<=$NumberOfSessionVariables; $i++)

{

$_SESSION['xxxxxxx'.$i]=0;

}

xxxxxx is the catagory name, I have 5 names.

 

please read i will extract and post your request...

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.