Results 1 to 8 of 8

Thread: Adding code before and after a link

  1. #1
    Join Date
    Jun 2003
    Posts
    3

    Default Adding code before and after a link

    Is thier any where you can edit so that a certain piece of code is added to all out going links? Example:

    http://www.yoursite.com/go.php?id=1 will take you to yahoo.com becuase :id=1 was submitted as www.yahoo.com

    Now lets say you want to add like a tracking code so that when the link on your site is clicked would produce the following results:

    when this link is clicked http://www.yoursite.com/go.php?id=1 would produce these results /beginingcode=www.yahoo.com&endcode

    Basically you want /beginingcode and endcode added to all the out links that are clicked without having to edit all the links in the database. Confused yet? =)


    Shane

  2. #2
    Join Date
    Apr 2003
    Location
    Atlanta GA
    Posts
    3,395

    Default

    can you be a little more specific: what is begincode and endcode?

    Are you talking about some click counter code?
    esm
    "The older I get, the more I admire competence, just simple competence, in any field from adultery to zoology."

    .

  3. #3
    Join Date
    Jun 2003
    Posts
    3

    Default

    it is not a counter code but a link skimming code. where as i can set a url to send a certain % to other sites or a certain % to the actual url.

    if a link is submitted as http://www.yahoo.com i want it so that when it is clicked it would produce the result:

    /cgi-bin/skim/c.cgi?url=http://www.yahoo.com&p=70

    basically that would call the cgi script i have on my server and send 70% of clicks to gallery and the other 30% where ever I have my other script point it =)

    I basically need it so that /cgi-bin/skim/c.cgi?url= is automatically placed in front of the submitted url and &p=70 is placed at the back of the url on click.

    thanks!
    Shane

  4. #4
    Join Date
    Aug 2001
    Location
    Indonesia
    Posts
    3,732

    Default

    Do you trying to passing variables to target link?
    It could be useful if you want to use 3rd party counter, ads tracking, etc.

    To do this you need to hack go.php and link.class.php
    Here is the direction:
    1. Pass the variables to go.php
    2. You need to change this code in go.php to receive your variables line 40-47
    Code:
      if(!in_array($id,$ses_links) || count($ses_links)==0) {
        $_SESSION['indexu_session_links'] = $_SESSION['indexu_session_links']."$id;";
        
        $links_obj->Go($id,true,$var1,$var2);
    	}
    	else {
    	  $links_obj->Go($id,false,$var1,$var2);
    	}
    3. Edit /lib/link.class.php function Go() line 2836, to receive your var
    Code:
    function Go($id,$count=true,$var1,$var2) {
    Line 2875
    Code:
    $url = $var1.$url.$var2;
    header("Location: $url");
    Do not try it yet, but logically work

  5. #5
    Join Date
    Jun 2003
    Posts
    3

    Default

    where would i define what $var1,$var2 is? so it knows that
    $var1 produces /cgi-bin/skim/c.cgi?url=
    $var2 produces &p=70

    Thanks!
    Shane

  6. #6
    Join Date
    Apr 2003
    Location
    Atlanta GA
    Posts
    3,395

    Default

    Originally posted by shanet
    where would i define what $var1,$var2 is? so it knows that
    $var1 produces /cgi-bin/skim/c.cgi?url=
    $var2 produces &p=70

    Thanks!
    Shane
    if it is the same for EVERY link, then

    DO NOT change go.php
    Code:
      if(!in_array($id,$ses_links) || count($ses_links)==0) {
        $_SESSION['indexu_session_links'] = $_SESSION['indexu_session_links']."$id;";
        
        $links_obj->Go($id,true);
    	}
    	else {
    	  $links_obj->Go($id,false);
    	}
    and change the go function in link.class.php
    Code:
      function Go($id,$count=true) {
    		
    		// get current hits
        $query = "select hits, url from $this->table_name where link_id=$id";
        $result = $this->db_connect->Execute($query);
        $url = $result->Fields("url");
        $hits = $result->Fields("hits");
    
    		if($count) {
          // update hits
          $query = "update $this->table_name set hits = ($hits + 1) where link_id = $id";
          $result = $this->db_connect->Execute($query);
        		
    		}
    $url = "/cgi-bin/skim/c.cgi?url=".$url."&p=70";
        header("Location: $url");
      }
    If $var1, $var2 change from link to link, then you will need to do what dody suggests and also, probably add 2 fields to your database and put the results of the query in go.php in as variables to calling the go function.
    esm
    "The older I get, the more I admire competence, just simple competence, in any field from adultery to zoology."

    .

  7. #7
    Join Date
    Aug 2001
    Location
    Indonesia
    Posts
    3,732

    Default

    Yes, good esm. You have better and simpler modification.

  8. #8
    Join Date
    Apr 2003
    Location
    Atlanta GA
    Posts
    3,395

    Default

    but only if it is the same for EVERY link.

    Otherwise, he would probably need to do what you suggest. Plus, somehow identify what link got which set of counter codes.
    esm
    "The older I get, the more I admire competence, just simple competence, in any field from adultery to zoology."

    .

Posting Permissions

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