Zen Cart Logo
Forums / General Questions / I want to set my own cookie or session variable

I want to set my own cookie or session variable

Locked

Views: 2,236

Results 1 to 8 of 8
This thread is locked. New replies are disabled.
19 Feb 2010, 5:18 PM
#1
rweeks avatar

rweeks

New Zenner

Join Date:
Jul 2008
Location:
San Diego, CA
Posts:
45
Plugin Contributions:
0

I want to set my own cookie or session variable

Here's what I an trying to do:

Affiliate has link on their site that comes to a custom landing page.
To make this link simple and relevant, the link is to mystore/theirName/index.php
This index file will then redirect to that customer's unique page (probably an EZ-Page).
In the index.php on the landing page, I want to set a cookie or session variable with the referral code, so if they get to the log in page, the referral code will be filled automatically from the cookie/session variable.
Note: in these test I am linking straight to the login page until I figure out how to get this to work.

Here is the Session code.

<?php

    session_start();
    $_SESSION["cust_ref"] = "theirName;
    header('Location: ' . 'http://' . $_SERVER['HTTP_HOST'] . '/index.php?main_page=login' );
    exit();
?>
```And for cookie.  I also tried setrawcookie.
<? header('Location: ' . 'http://' . $_SERVER['HTTP_HOST'] . '/index.php?main_page=login' ); setcookie("cust_ref","[I]theirName[/I]"); exit(); ?>

<? echo "REFERRAL CODE >> " . $_SESSION["cust_ref"] . " <<";  ?>

OR

<? echo "REFERRAL CODE >> " . $_COOKIE["cust_ref"] . " <<"; ?>

Both of these are empty.

Any suggestions are appreciated. 
 Or is there a better method that I have not considered.

Thanks
19 Feb 2010, 5:29 PM
#2
vger avatar

vger

Past Contributor

Join Date:
Nov 2004
Location:
Norfolk, United Kingdom
Posts:
3,189
Plugin Contributions:
0

Re: I want to set my own cookie or session variable

Or is there a better method that I have not considered.

I think you are trying to reinvent the wheel.

http://jam.jrox.com/

Vger

19 Feb 2010, 5:59 PM
#3
rweeks avatar

rweeks

New Zenner

Join Date:
Jul 2008
Location:
San Diego, CA
Posts:
45
Plugin Contributions:
0

Re: I want to set my own cookie or session variable

Perhaps, but I need a wheel for a wagon, not a race car.:P
Tried JROX, but I am on a windows server and could not get it to work.

20 Feb 2010, 4:36 AM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: I want to set my own cookie or session variable

rweeks:

Tried JROX, but I am on a windows server and could not get it to work.
I've not heard of any specific limitations preventing it from working on a windows server.
Granted, I still don't understand why people use windows servers for internet hosting these days. Too many problems.

20 Feb 2010, 4:39 AM
#5
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: I want to set my own cookie or session variable

rweeks:

Here's what I an trying to do:

Affiliate has link on their site that comes to a custom landing page.
To make this link simple and relevant, the link is to mystore/theirName/index.php
This index file will then redirect to that customer's unique page (probably an EZ-Page).
In the index.php on the landing page, I want to set a cookie or session variable with the referral code, so if they get to the log in page, the referral code will be filled automatically from the cookie/session variable.

You said you're trying to do this on "landing pages" ... which sounds like you're talking about files OUTSIDE of Zen Cart? If you're going to do that, it gets rather complicated.
But, you could try adding this to the .php file they're landing on before being sent to the Zen Cart page:

<?php 
  include ('/path/to/zencart/includes/application_top.php');
  $_SESSION['cc_id'] = [B]12345[/B];
  zen_redirect(zen_href_link(FILENAME_LOGIN, '', 'SSL'));
?>

Be sure to replace 12345 with the actual coupon_id number found in the coupons table in the database. You cannot put the coupon redemption-code there. It must be the system's internal coupon_id number.

20 Feb 2010, 6:11 AM
#6
rweeks avatar

rweeks

New Zenner

Join Date:
Jul 2008
Location:
San Diego, CA
Posts:
45
Plugin Contributions:
0

Re: I want to set my own cookie or session variable

DrByte, thanks for the suggestion. Still no luck.

If I abandon the idea of a page outside Zen-Cart and use an EZ-page instead.

Is there an issue with using PHP code on the ez-pages? Can seem to get any PHP code to work.

20 Feb 2010, 8:23 AM
#7
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: I want to set my own cookie or session variable

Ez-pages do not process PHP, only HTML (and javascript...)
There is a mod to allow PHP in ez-pages, or you could create new define pages which do allow PHP inherently (see the About Us mod in Free Addons).

20 Feb 2010, 10:44 AM
#8
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: I want to set my own cookie or session variable

rweeks:

Is there an issue with using PHP code on the ez-pages? Can seem to get any PHP code to work.
What exactly are you wanting to do on those pages? Is there something that MUST be done in the ez-page code part? or can the "code" you need to run be run in another way? It really depends on what exactly you need to accomplish. It's often better to explain what the end result needs to be, rather than pre-think yourself into a box that limits you to a certain course of action.