"if anchor" Help Any Ideas? Coders Inside

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • IllTestYourGirls
    Ah My Balls
    • Feb 2007
    • 14311

    #1

    "if anchor" Help Any Ideas? Coders Inside

    I am trying to show a set of ads for a group of about 20 sites or so and another set of sites another ad but show a different set of ads for everyone else. This is what I have for a code

    Code:
    <?
    $ref = getenv('HTTP_REFERER');
     $anchor = preg_replace("/http:\/\//i", "", $ref);
     $anchor = preg_replace("/^www\./i", "", $anchor);
     $anchor = preg_replace("/\/.*/i", "", $anchor);
    
    if ($anchor=="domain.com")
    { ?>ads<?}
    
    if (($anchor === "domain1.com") OR ($anchor === "domain2.com") OR ($anchor === "domain3.com")) 
    { ?>ad space here<?}
    
    else { ?>other ad here<?}
    ?>
    Problem is the code is showing both the if and the else ads. Any ideas how to fix it?
  • Nembrionic
    Confirmed User
    • Feb 2003
    • 2424

    #2
    try elseif

    Comment

    • Nembrionic
      Confirmed User
      • Feb 2003
      • 2424

      #3
      Also, what is "===" doing there? There's one too many.
      Should be "=="

      Comment

      • grumpy
        Too lazy to set a custom title
        • Jan 2002
        • 9870

        #4
        try == ;)
        Don't let greediness blur your vision | You gotta let some shit slide
        icq - 441-456-888

        Comment

        • Tempest
          Too lazy to set a custom title
          • May 2004
          • 10217

          #5
          Code:
          <?php
          
          	$ad = 'default';
          
          	$ref = (isset($_SERVER['HTTP_REFERER']) ? strtolower($_SERVER['HTTP_REFERER']) : '');
          
          	if( $ref != '' ){
          
          		$info = parse_url($ref);
          
          		if( $info !== false && isset($info['host']) ){
          
          			$domain = preg_replace('/^(www\.)+/', '', $info['host']);
          
          			if( in_array($domain, array('domain1.com', 'domain2.com')) ){
          
          				$ad = 'ad1';
          
          			}elseif( in_array($domain, array('domain3.com', 'domain4.com')) ){
          
          				$ad = 'ad2';
          			}
          		}
          	}
          
          	echo $ad;
          ?>

          Comment

          • IllTestYourGirls
            Ah My Balls
            • Feb 2007
            • 14311

            #6
            Originally posted by Nembrionic
            try elseif
            Tried this, it seems to only work when I have

            Code:
            elseif ($anchor=="")
            But I want the else if to be all other traffic. Not broken down by referring domains. Any suggestions for that?

            Originally posted by Nembrionic
            Also, what is "===" doing there? There's one too many.
            Should be "=="
            Originally posted by grumpy
            try == ;)
            Ok took out the extra "=" 's.

            Comment

            • Tempest
              Too lazy to set a custom title
              • May 2004
              • 10217

              #7
              Code:
              <?php
              $ref = getenv('HTTP_REFERER');
              $anchor = preg_replace("/http:\/\//i", "", $ref);
              $anchor = preg_replace("/^www\./i", "", $anchor);
              $anchor = preg_replace("/\/.*/i", "", $anchor);
              
              if( $anchor=="domain.com" ){
              
              ?>ads<?
              
              }elseif( $anchor == "domain1.com" || $anchor == "domain2.com" || $anchor == "domain3.com" ){
              
              ?>ad space here<?
              
              }else{
              
              ?>other ad here<?
              
              }
              ?>

              Comment

              • IllTestYourGirls
                Ah My Balls
                • Feb 2007
                • 14311

                #8
                Originally posted by Tempest
                Code:
                <?php
                $ref = getenv('HTTP_REFERER');
                $anchor = preg_replace("/http:\/\//i", "", $ref);
                $anchor = preg_replace("/^www\./i", "", $anchor);
                $anchor = preg_replace("/\/.*/i", "", $anchor);
                
                if( $anchor=="domain.com" ){
                
                ?>ads<?
                
                }elseif( $anchor == "domain1.com" || $anchor == "domain2.com" || $anchor == "domain3.com" ){
                
                ?>ad space here<?
                
                }else{
                
                ?>other ad here<?
                
                }
                ?>
                hmmm not showing it.

                Comment

                • Tempest
                  Too lazy to set a custom title
                  • May 2004
                  • 10217

                  #9
                  Originally posted by IllTestYourGirls
                  hmmm not showing it.
                  Not sure.. Tested both things I posted and they worked perfectly for me.

                  Comment

                  • blackmonsters
                    Making PHP work
                    • Nov 2002
                    • 20970

                    #10
                    If (used PERL) {
                    x= "you'd be through already";
                    }

                    Free Open Source Live Aggregated Cams Script (FOSLACS)

                    Comment

                    • IllTestYourGirls
                      Ah My Balls
                      • Feb 2007
                      • 14311

                      #11
                      Originally posted by Tempest
                      Not sure.. Tested both things I posted and they worked perfectly for me.
                      Strange it is working now, must have been a cache issue. Thanks

                      Comment

                      • IllTestYourGirls
                        Ah My Balls
                        • Feb 2007
                        • 14311

                        #12
                        Originally posted by blackmonsters
                        If (used PERL) {
                        x= "you'd be through already";
                        }

                        If I knew what the fuck I was doing Id be done too

                        I know just enough to get myself into trouble.

                        Comment

                        • sarettah
                          see you later, I'm gone
                          • Oct 2002
                          • 14301

                          #13
                          Here is a different way to do it. Not saying it's better, just different ;p

                          Code:
                          <?php
                          // Housekeeping
                          
                          // Initialize stuff
                          $domain=array();
                          $ads=array();
                          
                          // define the ad that will be shown if the domain is not in your list 
                          $ad2use="defaultad";
                          
                          // define the various ads you will use for domains in your list
                          $ad1="ad 1 code goes here";
                          $ad2="ad 2 code goes here";
                          $ad3="ad 3 code goes here";
                          
                          // for each domain that you want an ad for define the domain in $domain[] and the ad in $ad[]
                          // I store everything like this lower case 
                          
                          // site group 1
                          $domain[1]="domain1";
                          $ads[1]=$ad1;
                          $domain[2]="domain2";
                          $ads[2]=$ad1;
                          
                          //site group 2
                          $domain[3]="domain3";
                          $ads[3]=$ad2;
                          $domain[4]="domain4";
                          $ads[4]=$ad2;
                          
                          // site group 3
                          $domain[5]="domain5";
                          $ads[5]=$ad3;
                          
                          // etc etc for as many site-ad groups as you want
                          
                          // End of Housekeeping
                          
                          // Mainline
                          
                          // check to see if there is anything in referer
                          if(isset($_SERVER['HTTP_REFERER']))
                          {
                            // loop through the domain list
                            for($domcnt=1;$domcnt<=count($domain);$domcnt++)
                            {
                              // is the domain name in the referer string?  Checking lowercase because I have the domain list lowercased  
                              if(substr_count(strtolower($_SERVER['HTTP_REFERER']),$domain[$domcnt])>0)
                              {
                                // if the domain was in the referer string then grab the associated ad
                                $ad2use=$ads[$domcnt];
                                // break out of the for... loop
                                $break;
                              }
                            }
                          }
                          
                          // put the selected ad up there
                          echo $ad2use;
                          
                          // end of Mainline
                          
                          ?>
                          All cookies cleared!

                          Comment

                          • Nembrionic
                            Confirmed User
                            • Feb 2003
                            • 2424

                            #14
                            Originally posted by sarettah
                            Here is a different way to do it. Not saying it's better, just different ;p

                            Code:
                            <?php
                            // Housekeeping
                            
                            // Initialize stuff
                            $domain=array();
                            $ads=array();
                            
                            // define the ad that will be shown if the domain is not in your list 
                            $ad2use="defaultad";
                            
                            // define the various ads you will use for domains in your list
                            $ad1="ad 1 code goes here";
                            $ad2="ad 2 code goes here";
                            $ad3="ad 3 code goes here";
                            
                            // for each domain that you want an ad for define the domain in $domain[] and the ad in $ad[]
                            // I store everything like this lower case 
                            
                            // site group 1
                            $domain[1]="domain1";
                            $ads[1]=$ad1;
                            $domain[2]="domain2";
                            $ads[2]=$ad1;
                            
                            //site group 2
                            $domain[3]="domain3";
                            $ads[3]=$ad2;
                            $domain[4]="domain4";
                            $ads[4]=$ad2;
                            
                            // site group 3
                            $domain[5]="domain5";
                            $ads[5]=$ad3;
                            
                            // etc etc for as many site-ad groups as you want
                            
                            // End of Housekeeping
                            
                            // Mainline
                            
                            // check to see if there is anything in referer
                            if(isset($_SERVER['HTTP_REFERER']))
                            {
                              // loop through the domain list
                              for($domcnt=1;$domcnt<=count($domain);$domcnt++)
                              {
                                // is the domain name in the referer string?  Checking lowercase because I have the domain list lowercased  
                                if(substr_count(strtolower($_SERVER['HTTP_REFERER']),$domain[$domcnt])>0)
                                {
                                  // if the domain was in the referer string then grab the associated ad
                                  $ad2use=$ads[$domcnt];
                                  // break out of the for... loop
                                  $break;
                                }
                              }
                            }
                            
                            // put the selected ad up there
                            echo $ad2use;
                            
                            // end of Mainline
                            
                            ?>
                            Not very efficient ;)

                            Comment

                            • Brujah
                              Beer Money Baron
                              • Jan 2001
                              • 22157

                              #15
                              Code:
                              <?php
                                header( 'Location: http://exxxpired.com' );
                                exit();

                              Comment

                              Working...