[eluser]jblack199[/eluser]
I have a URL that is like:
http://www.domain.com/grm/1051 the grm is static, and the 1051 is dynamic.. This is a network designator and an affiliate ID for that network for traffic...
Now, on this website I am using cookies and have it initially set in my welcome.php like so:
Code:
function __construct() {
parent::__construct();
if ($this->uri->segment(1) !== 'welcome') {
if (strlen($this->input->cookie('affNetwork') < 1)) {
if (strlen($this->uri->segment(1)) >= 1) {
$this->input->set_cookie('affNetwork', $this->uri->segment(1), time() + 60 * 60 * 24 * 365 * 10);
if (strlen($this->uri->segment(2)) >= 1) {
$this->input->set_cookie('affID', $this->uri->segment(2), time() + 60 * 60 * 24 * 365 * 10);
}
}
}
}
if (strlen($this->input->cookie('prospectId') >= 1)) {
header("Location: http://www.domain.com/congratulations/");
}
}
I do h ave my routes.php set to designate the route that the specific path should take..
Now, my issue becomes apparent in the index() function of welcome.php mainly..
Code:
public function index() {
$data['pageTitle'] = "Site Title";
$data['pageContent'] = 'home';
$data['affNetwork'] = $this->input->cookie('affNetwork');
$data['affID'] = $this->input->cookie('affID');
$this->load->view('template/constructor', $data);
}
the issue is, the affNetwork and affID cookies aren't being read at this point even though they are there and working... if i refresh the page, it will then read the cookies... if I close the browser and go to
http://www.domain.com/ it will also read the cookies...
it is worthy to note that i've got .htaccess in place to do a few things, so here is my htaccess file..
Code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ index.php/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
here is the entire welcome.php for you to check out..
Code:
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Welcome extends CI_Controller {
function __construct() {
parent::__construct();
if ($this->uri->segment(1) !== 'welcome') {
if (strlen($this->input->cookie('affNetwork') < 1)) {
if (strlen($this->uri->segment(1)) >= 1) {
$this->input->set_cookie('affNetwork', $this->uri->segment(1), time() + 60 * 60 * 24 * 365 * 10);
if (strlen($this->uri->segment(2)) >= 1) {
$this->input->set_cookie('affID', $this->uri->segment(2), time() + 60 * 60 * 24 * 365 * 10);
}
}
}
}
if (strlen(get_cookie('prospectId') >= 1)) {
header("Location: http://www.domain.com/congratulations");
}
}
public function index() {
$data['pageTitle'] = "site";
$data['pageContent'] = 'home';
$data['affNetwork'] = $this->input->cookie('affNetwork');
$data['affID'] = $this->input->cookie('affID');
if ($this->input->cookie('prospectId') != "") {
$data['prospectId'] = $this->input->cookie('prospectId');
} else {
$data['prospectId'] = "";
}
$data['ssdir'] = 'ahic';
$data['popper'] = 'front';
$this->load->view('template/constructor', $data);
echo "<pre>";
print_r($data);
echo "</pre>";
}
public function newProspect() {
$pdata = $this->input->post();
$ndata = explode(" ", $pdata['firstName']);
$pdata['firstName'] = $ndata[0];
if (sizeof($ndata) == 1) {
$pdata['lastName'] = "blank";
} else {
$pdata['lastName'] = $ndata[1];
}
$data = $this->ourcrm
->setUrl('transact')
->method('NewProspect')
->campaignId('5')
->postData($pdata)
->process();
// note that the line above is a custom API I wrote to work with our CRM.
$this->input->set_cookie('prospectId', $data['prospectId'], time() + 60 * 60 * 24 * 365 * 10);
$data['redirectURL'] = '/congratulations';
echo json_encode($data);
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
Any ideas? Basically I MUST set a cookie, because I need to keep these cookies on the system if the browser crashes or closes and the user comes back to the site...
1 cookie is there to automatically redirect the user from the first page if it even exists.. the other 2 are again for tracking information in our CRM which I use throughout the site to set the data, but is also read and set upon the user coming back to the site should the browser crash or close.
If anyone has any insight into something like this i'd be most appreciative... I've also tried the shorthand: get_cookie and set_cookie to no avail.
Thanks,
jblack199