Closed Thread
Thread Tools Search this Thread
Unread 8th Mar 2012, 02:45 PM   #1
Active Warrior
War Room Member
 
Join Date: 2010
Posts: 97
Thanks: 17
Thanked 0 Times in 0 Posts
Default
PHP cookie and dynamic insertion
Share on: 
fb share twitter share gplus share more share

Hello,

I'm trying set cookies for dynamic features. I've been able to get the on page code right that allows me to insert all dynamic features using a custom url string.

i.e.
http://mysites.com/dynamicpage.php?RA_kw=Keyword-
keyword&RA_survey_id=survey_id&RA_id=123&RA_img=im gname

As long as ALL variables are present in the incoming url cookie for each variable sets fine. Upon return visits, user is shown all dynamic cookied features.

Problem 1: If ALL the php variables are NOT present in the url, cookie doesn't set on individual basis.

i.e.

http://mysites.com/dynamicpage.php?RA_kw=Keyword-keyword

Here's the php code:

PHP Code:
<?php
/*    kw = ( Keywords)
    survey_id=survey_id (this variable doesn't change)
    id= ( survey number id)
    img = ( name of image to be pulled from php include.)*/
$kw = null;
$survey_id = null;
$id = null;
$img = null;

    if (isset(
$_COOKIE['RA_kw']) 
        && isset(
$_COOKIE['RA_survey_id'])
        && isset(
$_COOKIE['RA_id'])
        && isset(
$_COOKIE['RA_img']))
    {
        
//if cookie variables are already set
    
        //To Do Here:  maybe redirect
        
$kw = $_COOKIE['RA_kw'];
        
$survey_id = $_COOKIE['RA_survey_id'];
        
$id = $_COOKIE['RA_id'];
        
$img = $_COOKIE['RA_img'];
        
$_GET['RA_kw'] = $kw;
        
$_GET['RA_survey_id'] = $survey_id;
        
$_GET['RA_id'] = $id;
        
$_GET['RA_img'] = $img;
    }
    else
    {
        
//if cookie varialbes are not set yet

        //set Cookies
        
if (isset($_GET['RA_kw'])){
            
//kw parameter is set
            
setcookie('RA_kw', $_GET['RA_kw'], time() + 60*60*24*30);    //expires in 30 days.
            
$kw = $_GET['RA_kw'];
        }
        if (isset(
$_GET['RA_survey_id'])){
            
//survey_id parameter is set
            
setcookie('RA_survey_id', $_GET['RA_survey_id'], time() + 60*60*24*30);    //expires in 30 days.
            
$survey_id = $_GET['RA_survey_id'];
        }
        if (isset(
$_GET['RA_id'])){
            
//id parameter is set
            
setcookie('RA_id', $_GET['RA_id'], time() + 60*60*24*30);    //expires in 30 days.
            
$id = $_GET['RA_id'];
        }
        if (isset(
$_GET['RA_img'])){
            
//img parameter is set
            
setcookie('RA_img', $_GET['RA_img'], time() + 60*60*24*30);    //expires in 30 days.
            
$img = $_GET['RA_img'];
        }

        
//To Do Here: default page
    
}
?>
JayGreen is offline  
Unread 6th Apr 2012, 03:50 AM   #2
HyperActive Warrior
War Room Member
 
Big Squid's Avatar
 
Join Date: 2009
Location: Living between LA & SD
Posts: 205
Thanks: 27
Thanked 36 Times in 33 Posts
Default
Re: PHP cookie and dynamic insertion
Share on: 
fb share twitter share gplus share more share

Not certain what you want to happen. The reason the variables are not being set is because you are referencing something that isn't there.

How can the code $_GET['RA_kw'] from the url when it doesn't exist?
Big Squid is offline  
Unread 6th Apr 2012, 09:40 AM   #3
HyperActive Warrior
War Room Member
 
Earnie Boyd's Avatar
 
Join Date: 2012
Posts: 290
Thanks: 13
Thanked 46 Times in 46 Posts
Default
Re: PHP cookie and dynamic insertion
Share on: 
fb share twitter share gplus share more share

If the data is missing you will need a custom 404 page and let the user know the link cannot be processed as given.

Earnie Boyd is offline  
Unread 9th Apr 2012, 07:00 AM   #4
Warrior Member
 
Join Date: 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: PHP cookie and dynamic insertion
Share on: 
fb share twitter share gplus share more share

I think we are missing the point. The problem is that it should set some of the variables if they exist.

Try showing error/notices and put a die/exit to see the message. It maybe after checking one variable the code crashes.

Web Applications Developer
MWD
chinny is offline  
Closed Thread


Bookmarks

Tags
cookie, dynamic, insertion, php

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 11:40 AM.