Real Estate Forums
| Coding HTML, ASP, PHP, JAVA MYSQL and more. All coding questions should be asked here. |
![]() |
|
|
Thread Tools | Display Modes |
|
|||
|
I'm having other sites send visitors and need to track where the visitors are from so I use a variable to carry the "affiliate" ID number of the referrer in the url. I settled on using cookies (rather than sessions) to store that value because I wanted to 1) give the visitor freedom to roam around a bit before registering but mostly to 2) protect the commission of the affiliate if the visitor left, for example, and came back later from other than the affiliates site. I think I'll use a 30 day expiration, not that it matters much.
With all that said, I had never worked with cookies before but I do have them working, sort of. I was wondering if someone would double check the coding for me? It seems like they work sometimes while at other times they don't seem to work. To see them in action, 1) go to BungeeBones.com through the following link http://bungeebones.com/index.php/5/ (the "5" would be the var of the affiliate so you are entering the site as if referred there by affiliate #5). You will notice in the upper left of that index page the error tracking echoes of 1) the affiliate var value and 2) the variable values of two cookies. The code that generates the cookies is as follows: setcookie ("cookie1", "Bungee Bones", time()+3600); setcookie ("cookie2", "Bungee Bones rocks $upline_num times", time()+3600,"/bungee_jumpers"); The error tracking code shows that cookie one is set, but cookie 2 is empty as I think it should be because by the code I used I'm telling the cookie2 to apply to the bungee_jumpers folder, right? So far so good, I think, but this morning when I went to the site it seemed to have a hard time reporting a cookie. Next, at the top of the page is a link http://www.bungeebones.com/bungee_jumpers/register.php/ under the button "Add A Site". If I go there, there are also error tracking echoes of the cookie2 variable. I just went there and cookie2 isn't showing a value. I did a lot of debugging and had begun reporting it here in this post too but cut it out. It took a lot of playing around with deleting cookies but now the cookies are working and I haven't a clue why? I don't know if they are working consistently or not. Does anyone have any ideas what is causing this problem? Thanks Last edited by RESynergy; 02-05-2007 at 10:55 AM. |
|
|||
|
Just a quick update to the above post, I just tried them pages again and it has stopped carrying the cookie values?
|
|
|||
|
here is another update. Might save someone else problems. All the above was in the Firefox browser. I opened the pages in Explorer and the cookies worked fine.
|
|
|||
|
Yeah, in general, I think you're right about cookies. I never used them before for all those reasons. Anything that has to do with the ip, or $_SERVER['HTTP_REFERER'], or creating a session from a variable in the url all had the disadvantage that if someone came to mine from another site, browsed, left, and then returned again from their history or bookmarks then the site that sent them originally would be out of luck. That was the main reason I went with cookies. I suppose I could retrieve the visitors ip with $_SERVER['REMOTE_ADDR'} and save it together with the affiliate's number in the db for a while. But don't a lot of people have dynamic IPs? It doesn't sound like there are any perfect solutions to the problem does it?
I finally did get it mostly figured out. For some reason firefox was having a problem with them. I know what to do now if I have trouble but I don't know how that will do any good if others have trouble too. I don't undestand your saying that sessions wouldn't work? It would work for the one visit.The visitor could still roam, as the session preserves the sender's info. Oh yeah, something else about the cookies. Almost all of the users of this site will be webmasters. I doubt if many of them would have cookies blocked, but even if they do they'll know how to allow them. Last edited by RESynergy; 02-05-2007 at 11:19 PM. |
|
|||||
|
Quote:
Quote:
Quote:
Quote:
If you retrieved the affiliate ID some other way, yes a session could work. You would need to check your server's session configuration, though, as they are periodically flushed. Quote:
|
|
|||
|
Thanks Fergus, a lot of good pointers. Helped a lot. I haven't tackled the functions yet, but guess what? I think I'm grasping what classes are all about! I have a class snipet for password protecting pages and I had to insert the value from the cookie above into the class and eventually into a new column in the db. Got it. There were functions inside the class too that had to be modified so the whole thing helped clarified my understanding a little better about functions.
Would you know - Since functions can be inside a class, and since functions can be inside a function (right?) can a class be inside another class? if so, how would the new class have to be named? I was laughing at the thought because in a class they use $this->var so if another class is added can it be named $that-> var? If so, we could add another $the_other_thing-> var so we weo would have this, that, and the other thing to cover all the bases LOL. Gosh, that is bad! |
|
||||
|
I'm the office OOP (object-oriented programming) geek. It's a passion of mine. The path you start down working with classes is deceptively simple though. OOP is extremely powerful and flexible -- but it's also more of an investment in design. I recommend you study up on OOP and design patterns. It'll be well worth the time!
In OOP generally, yes, a class can be contained inside another class. That's called an "inner class". As far as I know this is not supported in PHP. However, you can store passes in a property of a class, in which case you would access it internally as: PHP Code:
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|