Forum Moderators: coopster

Message Too Old, No Replies

how do i keep information during all session

         

michal317

3:46 pm on Jun 30, 2006 (gmt 0)

10+ Year Member



So this is my problem:
i want to detect one's refferal and according to it send him out with certain parm.
i know how to detect the refferal, but how do I keep it all along the session?
any suggestions?

jatar_k

5:07 pm on Jun 30, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you could just take the referer and store it into the session

michal317

6:29 pm on Jun 30, 2006 (gmt 0)

10+ Year Member



OK - how do I do that?

jatar_k

7:08 pm on Jun 30, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



are you already using sessions?

if so then it is only a matter of adding it, something like

$_SESSION['referer'] = $_SERVER['HTTP_REFERER'];

if you aren't using sessions then I would probably just put it into a cookie, take a look at

set_cookie [php.net]

eeek

7:21 pm on Jun 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The details on using sessions are at [php.net...]

michal317

8:56 pm on Jun 30, 2006 (gmt 0)

10+ Year Member



OK. where to I do it? I use a CMS - so I don't have an index.htm file I can input the code.

the_nerd

9:25 pm on Jun 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your cms probably has one central file that is called with various parameters, e.g. cms.php?page=1. If you don't use mod rewrite to make up virtual names (e.g. page1.htm, page2.htm ...) just look at this file (in my example cms.php) and try to insert the code that has been mentioned before. Look up how to start a session first.

Make sure you only set the session variable for the referrer once - if it hasn't been set before, or you'll overwrite the external referer with internal ones. (from your own web site)

If that doesn't help, pls let me know which cms you use.

michal317

2:16 pm on Jul 1, 2006 (gmt 0)

10+ Year Member



Hi!
Well I do use mod rewrite to change my the look of my links.
I use mambo - if you are familiar with it.
I tried maybe to insert the information into the DB, but I don't know at which stage to collect it. I need to collect if once, at the entrance of a user.
If you can suggest domething for me - it will be of great help.
thanks!

the_nerd

10:01 pm on Jul 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ok, I tried something for you.
Disclaimer: I have no clue about the inner works of mambo. just installed the software out of the box.

All the music seems to play in a file names index.php in the mambo root directory.

After the <?php - stuff I opened a session:

session_start();

And at the very end of this file I added this:

if (!isset ($_SESSION['referer'])) {
$_SESSION['referer'] = $_SERVER['HTTP_REFERER'];
echo "new referer logged: " . $_SESSION['referer'];
}
else {
echo "Referer has been set before this: " . $_SESSION['referer'];
}

Seems to work as intended:

1st call of a page:

new referer logged: [testserver...]

2nd and thereafter:
Referer has been set before this: [testserver...]

So, this seems to be a possibility. But simply opening a session might bring problems - maybe mambo does that on itself somewhere down in the code and you break it this way. But it may be a starting point foor you.

Good luck, nerd.

michal317

5:28 am on Jul 2, 2006 (gmt 0)

10+ Year Member



I don't know how to say it, but....
IT WORKS!

So simple.
I can't tell you how much I appriciate it.

cheers,
Michal.

michal317

6:42 am on Jul 2, 2006 (gmt 0)

10+ Year Member



Just one more question...
Don't I have to close the session?

michal317

10:15 am on Jul 2, 2006 (gmt 0)

10+ Year Member



OK - found a problem I can't resolve.
I tried to close the session, but it still saves the information.
What happens if a few people enter the site?

the_nerd

1:48 pm on Jul 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



should be no problem - everybody gets his own session.

whoisgregg

10:22 pm on Jul 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



session_destroy is what you would use to completely remove that session's data from the server.

session_destroy() destroys all of the data associated with the current session. It does not unset any of the global variables associated with the session, or unset the session cookie.

In order to kill the session altogether, like to log the user out, the session id must also be unset. If a cookie is used to propagate the session id (default behavior), then the session cookie must be deleted. setcookie() may be used for that.


from [php.net...]