How to check for $_GET value and set variable as that value - noob please help!

Discussion in 'PHP' started by effectivesite, Oct 11, 2011.

  1. #1
    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)

    
    
    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;
    		}
    	}
    }
    
    PHP:
    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.
     
    Solved! View solution.
    effectivesite, Oct 11, 2011 IP
  2. #2
    I haven't tested this but give this a try,
    
    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;
    	}
    }
    
    PHP:
     
    HuggyEssex, Oct 11, 2011 IP
  3. effectivesite

    effectivesite Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    that works perfectly.

    Thanks so much for the help. I was struggling there.

    I'll definitely keep your contact details for projects in the future.
     
    effectivesite, Oct 12, 2011 IP