Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Sorry to moan.. but it makes me quite angry that this is getting so many points.

Not only is it a pretty dull code snippet for which a combination of Google Analytics and Google Webmaster Tools would do a better job, but also the code has many flaws.

Even with the blatant SQL injection fixed there's still redundancy in the database - why store results_url separately when you can just use something like

    echo '<a href="http://google.com/search?q='.htmlspecialchars($row['search_term']).'">results url</a>';
and save storing all that duplicate data for every referral?

There's also no error handling - what if you get a referral from example.com/google/page.html? Boom! undefined index 'q' on line 5.

Why's $refer being stored on line 1 only to switch back to using $_SERVER['HTTP_REFERER'] again on line 3?

Why copy $vars into three separate variables at all?

And even if all this was fixed and the code was perfect, what's the point of this submission? Why's it interesting? What do we learn from this?

Again, I know complaining like this is frowned upon, but now and then I think it's useful to have some discussion about what's a good submission and what's not. If this faded out at 10 points then the system would be working. As it is it's been highly ranked for hours.



Hi user24,

As the author of the post, I'd like to respond.

When I wrote the code for this example, my main point was simply to illustrate how to extract certain useful bits of data from Google's referrer URL, and explain what they mean.

I was not intending it to be production-ready code -- that's why there's no error handling.

Indeed, as one other commenter noted, the storing of the values in a database could have been left off entirely.

What's the point of the submission, you ask? Well, Google's referrer URL uses variables that are not very intuitive. Who would know, just by looking at it, that the "cd" value represented the position at which a link appears on the Google search results page?

So I wrote this post for people who might see this referrer in their logs and want to know what it means. And while Google Analytics and Google Webmaster Tools do provide essentially the same information (and more!) there may be limited cases in which a person might want to use the information contained in the referrer URL within their script, e.g. "Hey, you searched for such-and-such. Here are some other posts you might like."


Hey,

I didn't mean to offend. And I've also been guilty of releasing non-production-ready code.

And if you'd just included that kind of disclaimer clearly up front I don't think I'd have felt so compelled to comment on this.

As far as the point of the submission. Yes, I found it interesting to learn about Google's referers, but I think I'd rather have just read about that, rather than seeing the code too. It was unclear whether the article was "Hey lets deconstruct google referers" or "Hey lets play with some PHP". The former is interesting, the latter not.

Thanks for the reply.


I am learning just by reading the comments of you guys correcting/sh!tting on the poster. As a noob to PHP it is sometimes nice to see what not to do.


Oh there's some benefit to be squeezed out of it I agree. It was news to me that google are sending this info.

These comments aren't going to be available to everyone who hits OP's site. If we're lucky, it's not a popular site and no-one will see it. If we're unlucky, the next web app you use could be coded by someone self-taught by articles like this.


That's what the flag link is for.


yes, and I used it when I saw this submission back when it was on 7 points. But it appears that enough people didn't that this submission has remained on the front page for over 3 hours. So, as I explained, I felt that system of flagging wasn't working in this case and that a comment was warranted.

I could as well reply to your comment that that's what the downvote button is for.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: