Real Estate Forums

Coding HTML, ASP, PHP, JAVA MYSQL and more. All coding questions should be asked here.

Reply
 
Thread Tools Display Modes
Old 02-05-2007, 10:43 AM
RESynergy RESynergy is offline
Real Estate WebMaster
 
Join Date: Nov 2006
Posts: 109
RESynergy is on a distinguished road
Default newbie with cookies - they're working but not quite

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.
Reply With Quote
Old 02-05-2007, 01:24 PM
RESynergy RESynergy is offline
Real Estate WebMaster
 
Join Date: Nov 2006
Posts: 109
RESynergy is on a distinguished road
Default Re: newbie with cookies - they're working but not quite

Just a quick update to the above post, I just tried them pages again and it has stopped carrying the cookie values?
Reply With Quote
Old 02-05-2007, 04:43 PM
RESynergy RESynergy is offline
Real Estate WebMaster
 
Join Date: Nov 2006
Posts: 109
RESynergy is on a distinguished road
Default Re: newbie with cookies - they're working but not quite

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.
Reply With Quote
Old 02-05-2007, 05:56 PM
REW Fergus's Avatar
REW Fergus REW Fergus is offline
Real Estate Webmasters Staff
 
Join Date: Aug 2006
Location: Nanaimo, BC
Posts: 588
REW Fergus is on a distinguished road
Default Re: newbie with cookies - they're working but not quite

I'm not sure I'm totally sold on using cookies in this way. Cookies have the drawback of being easily disabled -- and frankly the use of cookies for this sort of tracking is very rarely in the user's interest, so I'm surprised they aren't disabled more. Also many applications that accept cookies will by default be configured only to accept cookies that are passed back to the originating and only the originating site. Sounds like trouble.

Sessions wouldn't work at all because they are server specific.

Is there a possibility of using $_SERVER['HTTP_REFERER'] to track the referring site? Note: this probably won't work on an IIS site. Most of the server out there are running Apache, and with very good reason. Another possibility is to have all tracked links contain a query string:
Code:
http://www.targetsite.com/?aid=somecode
__________________
Fergus Gibson
realestatewebmasters.com
Reply With Quote
Old 02-05-2007, 10:44 PM
RESynergy RESynergy is offline
Real Estate WebMaster
 
Join Date: Nov 2006
Posts: 109
RESynergy is on a distinguished road
Default Re: newbie with cookies - they're working but not quite

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.
Reply With Quote
Old 02-05-2007, 11:36 PM
REW Fergus's Avatar
REW Fergus REW Fergus is offline
Real Estate Webmasters Staff
 
Join Date: Aug 2006
Location: Nanaimo, BC
Posts: 588
REW Fergus is on a distinguished road
Default Re: newbie with cookies - they're working but not quite

Quote:
Originally Posted by RESynergy View Post
Yeah, in general, I think you're right about cookies. I never used them before for all those reasons.
We use them, and I don't really mean to say you can't. It's just important to recognize their limitations and lack of reliability. You can't really depend on them for core functionality. Kinda like Javascript.

Quote:
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.
Very true.

Quote:
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?
There probably isn't a perfect solution. Yes, it's true that the vast majority of Internet users have dynamic IPs. However, with the increasing use of always-on connections (e.g. DSL, Cable), those dynamic IPs aren't all the dynamic. I have had the same IP since I moved because my router renews it perpetually. But for dial-up users, sure, they'll probably have a different IP every time they arrive at your site.


Quote:
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.
The problem with using sessions is that they have no way to receive the affiliate ID in the first place. Sessions can only store, manipulate and read data on the one server. So if you were tracking $_SERVER['REMOTE_ADDR'] to a session, sure that could work fine. But you can't use them to get the affiliate ID from one server to another, which it sounded like you might be hoping you could do with a session.

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:
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.
I tend to think the Internet savvy are more of a problem. They are the folks who understand how cookies can be used counter to their interests, and they have enough computer knowledge to be comfortable reconfiguring their browsers to disallow cookies. I actually think webmasters are likely to be far worse than the general public, who don't understand what a cookie is, why they might not one, or how to turn them off.
__________________
Fergus Gibson
realestatewebmasters.com
Reply With Quote
Old 02-07-2007, 12:04 PM
RESynergy RESynergy is offline
Real Estate WebMaster
 
Join Date: Nov 2006
Posts: 109
RESynergy is on a distinguished road
Default Re: newbie with cookies - they're working but not quite

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!
Reply With Quote
Old 02-07-2007, 03:14 PM
REW Fergus's Avatar
REW Fergus REW Fergus is offline
Real Estate Webmasters Staff
 
Join Date: Aug 2006
Location: Nanaimo, BC
Posts: 588
REW Fergus is on a distinguished road
Default Re: newbie with cookies - they're working but not quite

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:
$this->classVariable->someMethod(); 
__________________
Fergus Gibson
realestatewebmasters.com
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Real Estate Webmasters on Facebook

For our members

Main Sections

IDX Coverage Areas

You can find us at

Spiders Welcome

All times are GMT -7. The time now is 06:56 PM.


Powered by vBulletin®
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.