Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-11-2011, 08:30 PM   PM User | #1
effectivesite
New to the CF scene

 
Join Date: Jun 2011
Posts: 8
Thanks: 3
Thanked 0 Times in 0 Posts
effectivesite is an unknown quantity at this point
check $_GET isset then write it to variable? Please help

Hey guys I'm a php noob who's inherited this site and can't figure out how to check if the url has a variable in it, then set that variable as something else (sorry if the jargon's wrong)

PHP Code:

function adExtNo($defaultExt '1004'){
    if(isset(
$_COOKIE[__FSCOOKIE_PRINT_EXT])){ //Detect custom print media ad ext number
        
$adCookie $_COOKIE[__FSCOOKIE_PRINT_EXT];
        return 
$adCookie;
    }else{ 
//Else detect ppc ad ext number
        
if(isset($_COOKIE[__FSCOOKIE_PPC_EXT])){
                
$adCookie $_COOKIE[__FSCOOKIE_PPC_EXT];
                return 
$adCookie;
    }else{ 
//Else detect ppc ad ext number in url
        
if(isset($_GET[ppc_ext])){
                
$adCookie $_GET[ppc_ext];
                return 
$adCookie;
        }else{ 
//Else just set ext number to web default
                
return $defaultExt;
        }
    }

Currently the code checks for a variable in a cookie then sets $adCookie as that value (I believe). If there's no cookie value then I want it to get the value from the tagged url, and if the url isn't tagged then defaultExt.

I've been trying to add the second }else{ statement to detect a variable in the URL (i.e. url.com/?ppc_ext=1234) then if it exists set $adCookie to that value, else return $defaultExt.

does anyone know how to do this?
Thanks for any help.
effectivesite is offline   Reply With Quote
Old 10-11-2011, 08:56 PM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,046
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
I think you need single quotes as shown:

if(isset($_GET['ppc_ext'])){
$adCookie = $_GET['ppc_ext'];
return $adCookie;
mlseim is offline   Reply With Quote
Users who have thanked mlseim for this post:
effectivesite (10-18-2011)
Old 10-18-2011, 08:29 PM   PM User | #3
effectivesite
New to the CF scene

 
Join Date: Jun 2011
Posts: 8
Thanks: 3
Thanked 0 Times in 0 Posts
effectivesite is an unknown quantity at this point
Quote:
Originally Posted by mlseim View Post
I think you need single quotes as shown:

if(isset($_GET['ppc_ext'])){
$adCookie = $_GET['ppc_ext'];
return $adCookie;
Thanks mlseim. Finally got it working without it but I'll try that if it's better coding practice.

just in case anyone else was in need of this, here it is thanks to HuggyEssex on digitalpoint

PHP Code:
function adExtNo($defaultExt '1004'){
    if(isset(
$_COOKIE[__FSCOOKIE_PRINT_EXT])) {
        
//Detect custom print media ad ext number
        
$adCookie $_COOKIE[__FSCOOKIE_PRINT_EXT];
        return 
$adCookie;
    }elseif(isset(
$_COOKIE[__FSCOOKIE_PPC_EXT])) {
        
//Else detect ppc ad ext number
        
$adCookie $_COOKIE[__FSCOOKIE_PPC_EXT];
        return 
$adCookie;
    }elseif(isset(
$_GET[ppc_ext])) {
        
//Else detect ppc ad ext number in url
        
$adCookie $_GET[ppc_ext];
        return 
$adCookie;
    }else{
        
//Else just set ext number to web default
        
return $defaultExt;
    }

effectivesite is offline   Reply With Quote
Reply

Bookmarks

Tags
$_get, isset, url variable

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 05:33 AM.


Advertisement
Log in to turn off these ads.