2

I am quite new to php.. so be kind. :D

Anyway, I am in the process of creating a simple function that stores information about a certain visitor that has been referred to us. With referred I mean I have create affiliate links for them to use in promoting a certain page on our website.

So I've read a little about sessions and session variables.

My idea is that I get who refers a sale via url parameters in the referral link and storing it within a session variable.

Say I have this referral link - www.example.com/?referralid=affiliateone

When people click on that link, they will go to a page and the function will work. Storing the referralid parameters within a session variable.

$_SESSION["referrer"] == $_GET['referralid'];

Would that work?


So while the visitor is in the website this session variable will be carried..That's the only thing I want to know. Will this work for multiple people accessing the page?

Do they get different session? And in that case, different referral id url parameter installed in their session variable?

I hope I make sense. I appreciate all your answers.

jowettgo
  • 21
  • 2
  • Putting php session variables into a search engine gave me a whole bunch of options on learning to use php. I suggest finding one and reading it. Including these stackoverflow questions, which should answer your question: http://stackoverflow.com/questions/5489365/how-to-use-store-and-use-session-variables-across-pages and http://stackoverflow.com/questions/8726268/how-to-get-session-variables-using-session-id – Guy Schalnat Jul 14 '15 at 07:51

1 Answers1

0

Yes, PHP Sessions are created per individual user that's browsing the specific page. so in your case, you can get the referral ID and save it in a session and carry out the rest of the process.

Nilan
  • 94
  • 3
  • Thanks for the comment Nilan... this site I am building is static. Do I need to put session_start() in every page to preserve the session variables that was initially set using the parameters in the url? Or no need? I take it that the session terminate when the visitor closes their browser right? – jowettgo Jul 14 '15 at 08:25
  • I got the answer and it must be there in any page. :D – jowettgo Jul 14 '15 at 08:34
  • your welcome. and yes It should be in every page, you can create a separate php file which contains the session_start() and include it in top of the other pages. it would be easy. – Nilan Jul 14 '15 at 09:30