CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   check $_GET isset then write it to variable? Please help (http://www.codingforums.com/showthread.php?t=240647)

effectivesite 10-11-2011 08:30 PM

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.

mlseim 10-11-2011 08:56 PM

I think you need single quotes as shown:

if(isset($_GET['ppc_ext'])){
$adCookie = $_GET['ppc_ext'];
return $adCookie;

effectivesite 10-18-2011 08:29 PM

Quote:

Originally Posted by mlseim (Post 1146319)
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;
    }




All times are GMT +1. The time now is 06:13 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.