1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Problematic link-masking script

Discussion in 'PHP' started by lucab, Jan 22, 2007.

  1. #1
    I have been trying to troubleshoot this script and figure out what the problem with it is. However, I am a complete rookie when it comes to PHP so I am having great difficulty getting it to run. I am near the beginning of the PHP tutorial I am using and I am afraid it will be quite some time before I am able to figure this out.

    I am simply trying to mask links, for example for affiliates. I know this has been covered a lot before, but I don't want to use .htaccess and mod_rewrite. I want to do this the right way. Here is the script I am trying to implement:

    <?
    function check_search_engine()
      if ($a == 1) {
        header("Location: http://www.affiliate.com/link.php");
        exit;
      }
    {
    	IF(!isset($_SERVER['HTTP_USER_AGENT']))
    	{
    		$user_agent = '';
    	}
    	ELSE
    	{
    		$user_agent = $_SERVER['HTTP_USER_AGENT'];
    	}
    
    	$search_engines[] = 'Fast';
    	$search_engines[] = 'Slurp';
    	$search_engines[] = 'Ink';
    	$search_engines[] = 'Atomz';
    	$search_engines[] = 'Scooter';
    	$search_engines[] = 'Crawler';
    	$search_engines[] = 'bot';
    	$search_engines[] = 'Genius';
    	$search_engines[] = 'AbachoBOT';
    	$search_engines[] = 'AESOP_com_SpiderMan';
    	$search_engines[] = 'ia_archiver';
    	$search_engines[] = 'Googlebot';
    	$search_engines[] = 'UltraSeek';
    	$search_engines[] = 'Google';
    
    	foreach ($search_engines as $key => $value) 
    	{
    		IF($user_agent != '')
    		{
    			if(strstr($user_agent, $value)) 
    			{
    				$is_search_engine = 1;
    			}
    		}
    	}
    
     	IF(isset($is_search_engine)) 
    	{
    		return TRUE;
     	}
     	else
     	{
    		return FALSE;
     	}
    }
    ?>
    <?
    if (check_search_engine() == TRUE) {
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta name="robots" content="noindex, nofollow">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    </body>
    </html>
    <?
    } else {
      $a = $_REQUEST['a'];
      if ($a == 1) {
        header("Location: http://www.affiliate.com/link1.php");
        exit;
      }
      if ($a == 2) {
        header("Location: http://www.affiliate.com/link2.php");
        exit;
      }
      if ($a == 3) {
        header("Location: http://www.affiliate.com/link3.php");
        exit;
      }
    }
    ?>
    PHP:
    This it the error message I get when I try to run it: "Parse error: syntax error, unexpected T_IF, expecting '{' in ...index.html/products/info.php on line 3."

    I have tried to add a '{' in different spots, or move it around a little bit. However, none of this worked.

    Any help would be greatly appreciated.
     
    lucab, Jan 22, 2007 IP
  2. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #2
    What is the function of this line?

    I am a newb also. Never seen a line like this in a script.

    You have an extra space between If and the ( . Also don't you need a ; at the end of that line?
     
    Colbyt, Jan 22, 2007 IP
  3. lucab

    lucab Peon

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I believe that is to start the PHP header redirect. Perhaps I am getting confused, but that is what I believe it is for.

    When the script is called upon, for example <a href="http://domain.com/index.html/products/link.php?=a">here</a>, the script redirects to the proper aff link.
     
    lucab, Jan 22, 2007 IP
  4. libneiz

    libneiz Peon

    Messages:
    9
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Try moving the last "{" to right after the function declaration, such that it reads:

    
    <?
    function check_search_engine() {
      if ($a == 1) {
        header("Location: http://www.affiliate.com/link.php");
        exit;
      }
      ......
    
    PHP:
    assuming you want the if ($a == 1) to be in the function declaration. I didn't read the whole snip.
     
    libneiz, Jan 22, 2007 IP
    lucab likes this.
  5. lucab

    lucab Peon

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thank you for your help. The interpreter seems to have gotten past that point, but now I am getting this error message:

    "Parse error: syntax error, unexpected $end in products/info.php on line 84"
     
    lucab, Jan 22, 2007 IP
  6. jgarrison

    jgarrison Peon

    Messages:
    66
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You're missing the opening brace: function check_search_engine() {

    -Jim
     
    jgarrison, Jan 22, 2007 IP
  7. lucab

    lucab Peon

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thank you jgarrison for your assistance. But I actually spotted that myself, and now I am getting a different error. "Parse error: syntax error, unexpected $end in ...products/info.php on line 84" Once again I am lost.
     
    lucab, Jan 22, 2007 IP
  8. jgarrison

    jgarrison Peon

    Messages:
    66
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    function check_search_engine() {
    if ($a == 1) {
    header("Location: http://www.affiliate.com/link.php");
    exit;
    }
    { <---- DELETE THIS BRACE

    You have an extra open brace in the code.

    -Jim
     
    jgarrison, Jan 22, 2007 IP
  9. lucab

    lucab Peon

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Thank you very very very much sir. ++++rep
     
    lucab, Jan 22, 2007 IP