Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8159839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:03:33+00:00 2026-06-06T18:03:33+00:00

To build some simple analytics for our site – I am trying to capture

  • 0

To build some simple analytics for our site – I am trying to capture the source from where the user lands on our page and if he ends up registering – store the source in the database.

Since this code has to be on all the pages – I thought of adding it to the layout.phtml
This is what I have so far (just a rough draft)

$ref_cookie = $_COOKIE["xyzcom-referrer"];
if(!Zend_Auth::getInstance()->hasIdentity() && $ref_cookie==null) {
$ref=null;
$ref=$_GET['ref'];
if($ref==null || strlen($ref)==0)
    $ref= $_SERVER["HTTP_REFERER"];
//set in cookie incase user returns later and registers
setcookie("xyzcom-referrer",$ref);
}

Its pretty self explanatory – if the user is not logged in – I’m trying to get the referrer either thru the ref parameter or thru HTTP_REFERRER. The reason I’m storing it in a cookie is a user might visit the site today but sign up one week later.

So everytime a user registers, I will see if this cookie is set – if it is – I will get the value and insert it in the database as the referring source.

Is this the best way to approach this.
Or should I write like a controller plugin – if so how do I go about it.
Thanks for your tips.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:03:34+00:00Added an answer on June 6, 2026 at 6:03 pm

    The layout is not really the place for this sort of logic, so yes I would suggest moving it to a controller plugin. This should be straightforward, create a plugin class, register it with the front controller, and in the class create a preDispatch method (as explained in the manual) and move your code to that.

    There are also a few issues with your code:

    • You are assuming HTTP_REFERER will be set, but it may not be.

    • You are setting a session only cookie (that will be deleted when the user closes his/her browser) without a path (meaning if it is set in a sub-directory on your site it will not be available to your homepage). You’ll want to supply the 3rd and 4th parameters to setcookie() to address these problems.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a simple html page which include some text paragraph, during
I am starting to I am learning scala, and trying to build some simple
I want to build some package from source ( e2fsprogs to be more concrete)
I am trying to do some simple statistics on data I am pulling from
I'm trying to build a simple HTML table form that displays values from a
I am just trying to compile some simple example code I typed in from
During our build process, we run sqlldr to populate our database with some sample
I'm trying to build some .ascx controls into a class library for plugins for
I need to build a custom designed bar chart that displays some simple data.
I am currently trying to build some test code that uses Google C++ Test

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.