Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,395
    Thanks
    8
    Thanked 1,078 Times in 1,069 Posts
    I think you need single quotes as shown:

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

  • Users who have thanked mlseim for this post:

    effectivesite (10-18-2011)

  • #3
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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;
        }



  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •