SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    double whammy. browser detection and passing vars

    Here's my situation. I have three script, which I'll post portions of in a moment. One is variables.php, one is functions.php and one is newcust.php. Both variables and functions are includes of newcust. The problemS come in:
    [list=1][*]The browser detection, loosely take from Kevin Yank, designed for a PHP 4.2, register_globals environment. No matter what, all I am detecting is Mozilla, even when IE opens the page.[*]Here's where the sampling comes in. Look at www.barefooting.com/sales/newcust.php and go ahead and sign up for something. Notice that no matter what, it always goes with the $39.95 plan. The script involves two primary variables - $payment_code and $hosting_plan. For the sake of ease of coding and to just get it to work, I have hardcoded the value for $payment_code to equal 'monthly'.[/list=1]
    Enough of my jibber jabbering. Heres my code:
    Code:
    //functions.php file
    function inAgent($agent){
    	$notAgent=strpos($_SERVER['HTTP_USER_AGENT'],$agent)===false;
    	return(!$notAgent);
    }
    if(inAgent('MSIE 4')||inAgent('MSIE 5')){
    	if(inAgent('Mac')){
    		$browser=inAgent('MSIE 5')?'ie5mac':'ie4mac';
    		return($browser);
    	}
    	elseif(inAgent('Win')){
    		return("iewin");
    	}
    }
    elseif(!inAgent('MSIE')){
    	if(inAgent('Mozilla/5')||inAgent('Mozilla/6')){
    		return("ns6");
    	}
    	elseif(inAgent('Mozilla/4')){
    		if(inAgent('Mac')){
    			return("nsmac");
    		}
    		elseif(inAgent('Win')){
    			return("nswin");
    		}
    		else{
    			return("nsunix");
    		}
    	}
    }
    else{
    	return("unknown");
    }
    Code:
    //variables.php
    $browser=inAgent($_SERVER['HTTP_USER_AGENT']);
    if($browser == 'ns6') 
    	{
    	//Netscape 6-Mozilla variables
    	$sitecss 	= "../includes/barefootingMOZILLA.css";
    	$admincss	= "../includes/adminMOZILLA.css";
    	$inputfield = 25;
    	}
    else
    	{
    	//IE 5+ Variables
    	$sitecss 	= "../includes/barefootingIE.css";
    	$admincss 	= "../includes/adminIE.css";
    	$inputfield = 50;
    	}
    The whole source code for newcust.php is here:newcust.phps

    Thanks.

    Sketch
    Aaron Brazell
    Technosailor



  2. #2
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey Aaron.

    not sure about the browser detector. maybe try changing the inAgent() function to this:

    Code:
    function inAgent($agent) {
    	return strpos($_SERVER['HTTP_USER_AGENT'], $agent) !== false;
    }
    or maybe:

    Code:
    function inAgent($agent) {
    	return (strpos($_SERVER['HTTP_USER_AGENT'], $agent) !== false) ? 1 : 0;
    }


    with the hosting plans code, you have a lot of this

    PHP Code:
    if($hosting_plan 'really_foot'){ 
    instead of

    PHP Code:
    if($hosting_plan == 'really_foot'){ 
    which would make it go through all of the things and have $payment_code be whatever the last thing is. the $39.95 plan in this case.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  3. #3
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, cool. We're halfway there. The solution to the second problem is solved with the == instead of =.

    So the first problem is still unresolved. I have used your first code, and regardless of browser, I pull up Mozilla info andthe second code is opposite - regardless of browser, the IE info is returned.

    Sketch
    Aaron Brazell
    Technosailor



  4. #4
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    good re: the second.

    just noticed in the browser detect code; you have this

    Code:
    .....
    if(inAgent('MSIE 4')||inAgent('MSIE 5')){
    	if(inAgent('Mac')){
    		$browser=inAgent('MSIE 5')?'ie5mac':'ie4mac';
    		return($browser);
    	}
    	elseif(inAgent('Win')){
    		return("iewin");
    	}
    }
    .....
    why is there `return' in this code since it doesn't appear to be in a function?

  5. #5
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm. Good question. Cut and paste from COLIN!

    I guess the function is defined, then the rest is just implementing the function to get a result for $browser (used in variables.php). That's what it seems like to me. But you're right about the return. Let me try without that.

    Sketch
    Last edited by Sketch; Jun 9, 2002 at 21:40.
    Aaron Brazell
    Technosailor



  6. #6
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nope no change. I updated the links above. Mozilla still gets IE stuff.

    Sketch
    Aaron Brazell
    Technosailor



  7. #7
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Sketch
    hmmm. Good question. Cut and paste from COLIN! ...
    Well I am ever so SSSSOOOORRRRYYY! :mutters: Last time I look at one of your scripts :mutters:

    BTW, what do the ? and : signify there? I've been through the PHP manual and cannot figure that one out. Thanks.

    -Colin
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.

  8. #8
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    By the way, is return() only to be used exclusively in functions to return a value?

    -Colin
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.

  9. #9
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here we go, got it to work with an edited function and removal of the $browser definition line in variables.php:
    PHP Code:
    function inAgent($agent) {
        return (
    strpos($_SERVER['HTTP_USER_AGENT'], $agent) !== false) ? 0;
    }
    //function inAgent($agent){
    //    $notAgent=strpos($_SERVER['HTTP_USER_AGENT'],$agent)===false;
    //    return(!$notAgent);
    //}
    if(inAgent('MSIE 4')||inAgent('MSIE 5')){
        if(
    inAgent('Mac')){
            
    $browser=inAgent('MSIE 5')?'ie5mac':'ie4mac';
            
    //return($browser);
        
    }
        elseif(
    inAgent('Win')){
            
    $browser 'iewin';
            
    //return("iewin");
        
    }
    }
    elseif(!
    inAgent('MSIE')){
        if(
    inAgent('Mozilla/5')||inAgent('Mozilla/6')){
            
    $browser 'gecko';
            
    //return("ns6");
        
    }
        elseif(
    inAgent('Mozilla/4')){
            if(
    inAgent('Mac')){
                
    $browser 'ns4mac';
                
    //return("nsmac");
            
    }
            elseif(
    inAgent('Win')){
                
    $browser 'ns4win';
                
    //return("nswin");
            
    }
            else{
                
    $browser 'ns4unix';
                
    //return("nsunix");
            
    }
        }
    }
    else{
        
    $browser 'unknown';
            
    //return("unknown");

    Thanks for the help, MAtt AND Colin!

    Aaron
    Aaron Brazell
    Technosailor



  10. #10
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    goody.



    Originally posted by Aes
    BTW, what do the ? and : signify there? I've been through the PHP manual and cannot figure that one out.
    umm, the ternary operator.


    By the way, is return() only to be used exclusively in functions to return a value?
    generally. www.php.net/manual/en/function.return.php


Bookmarks

Posting Permissions

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