Results 1 to 6 of 6
  1. #1
    Member Core's Avatar
    Join Date
    March 16th, 2006
    Location
    Cornfield, Illinois
    Posts
    95
    Question Need PHP Code Checked
    Hello All,

    After reading about cloaking links I programmed a php script to query a database with my cj links. I put links where my CJ links that point to a page with this script which automatically redirects the user to the right CJ url pointed from the Database.

    Here is how I did it. I programmed the script and saved it in a php page called text.php and then for each of my links I assigned a specific id in the database called link_id. When I put my link in a web page in place of the cj link I would reference it as text.php?id=00001 . The ID variable was read by the php script which compared it to the link_id in the database. This script found the link_id and the CJ URL in my database associated with it and redirected the user to the merchant automatically with the header redirect. What I'm wondering is if I programmed it wrong. I output the query via the echo command and the url looks perfect but I wonder if it would keep sales from being tracked for some odd reason.

    Here is my text.php code:

    Code:
    <? $linkid = $_POST["id"]; 
    
     @ $db = mysql_pconnect("localhost", "username", "password");
    
    			if (!$db)
    			{
    			echo "Error: Could not connect to database";
    			
    			}
    			?><?
    
    	 mysql_select_db("cjlinks");
    		  	  $query = "select link_url from cjtable where link_id = '$id'";
    			  $result = mysql_query($query);
    			  $num_results = mysql_num_rows($result);
    			  
    			  for ($i=0; $i <$num_results; $i++) {
                 $row = mysql_fetch_array($result); 
    			 }
      
      $url = htmlspecialchars($row["link_url"]);
    
        header("Location: http://".$url."/?sid=".$linkid."");
    
      ?>
    Am I doing something wrong? I have had a lot of traffic and the clicks are registering but I have no sales.

    Thanks,
    Core

  2. #2
    Full Member markschok's Avatar
    Join Date
    January 18th, 2005
    Posts
    269
    $query = "select link_url from cjtable where link_id = '$id'";
    shouldn't this be,
    $query = "select link_url from cjtable where link_id = '$linkid";

    Also how is the CJ url stored in the DB? If you're storing the complete URL you don't need the http:// in the header line below.
    header("Location: http://".$url."/?sid=".$linkid."");
    since the header would then be output as http://http://www.************/click...sid=linkidcode

  3. #3
    Member Core's Avatar
    Join Date
    March 16th, 2006
    Location
    Cornfield, Illinois
    Posts
    95
    Hi Mark,

    I have the URLs stored in the db without the http://.

    I also just tweaked the code a bit because the $_post was not passing the id but saving it as $id which is why the query worked rather than using $linkid (I had tested this prior to implementation.) So I was getting the urls out of the db. I was just wondering if I was messing up the URLs when they were posted or if for some reason this way of redirecting would keep sales from posting.

    Here is my updated code:

    Code:
    <? $linkid = $_REQUEST["id"]; 
    
     @ $db = mysql_pconnect("localhost", "username", "password");
    
    			if (!$db)
    			{
    			echo "Error: Could not connect to database";
    			
    			}
    		
    
    	 mysql_select_db("cjlinks");
    		  	  $query = "select link_url from cjlink where link_id = '$linkid'";
    			  $result = mysql_query($query);
    			  $num_results = mysql_num_rows($result);
    			  
    			  for ($i=0; $i <$num_results; $i++) {
                 $row = mysql_fetch_array($result); 
    			 }
     
     if ($num_results > 0) {
      
      $url = htmlspecialchars($row["link_url"]);
    
        header("Location: http://".$url."/?sid=".$id."");
    	
    	}
    	
    	else
    	{
    	
    	header("Location: http://www.cjstoremainlink.com/click-xxx-xxx");
    
    }
      ?>
    Everything seems to work okay as far as the redirect goes and I am fairly certain that there is no way a parasite could overwrite and redirect since it is being done before being sent to the end-user. I will let you know if I start seeing sales. The products are not something I would use or I would do a test purchase.

    If the code works everyone is more than welcome to use it and I would be more than happy to post the sql statements that you could copy and paste into phpmyadmin or type in yourself to create the database and tables.

    Core

  4. #4
    Full Member markschok's Avatar
    Join Date
    January 18th, 2005
    Posts
    269
    If the links look like they're coming out of the DB and the redirect is working ok the next thing to check then would be the cookies. Clear your cookies, click a redirect and make sure the cookie is loaded. Also, allthough a parasite wouldn't overwtire on the redirect. The could pop a browser and overwrite once your user is on the merchants site.

    You could try loading a merchants URL that you would buy from in to your DB and doing a test purchase from there.

  5. #5
    Full Member markschok's Avatar
    Join Date
    January 18th, 2005
    Posts
    269
    woo hoo, my 200th post above, 2 dots and a new title.

  6. #6
    Member Core's Avatar
    Join Date
    March 16th, 2006
    Location
    Cornfield, Illinois
    Posts
    95
    First,

    Congrats on the 200th post! You've been busy.

    Secondly,

    My Code Works! I have had multiple sales today on that site and all the links on that site run through that code.

    Core

  7. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. Need php code work
    By RH&A in forum Programming / Datafeeds / Tools
    Replies: 3
    Last Post: March 21st, 2007, 08:03 AM
  2. what php include code do you use and...why?
    By Adrian in forum Programming / Datafeeds / Tools
    Replies: 23
    Last Post: February 28th, 2007, 01:03 PM
  3. php code
    By tvcrazyman in forum GoldenCAN
    Replies: 4
    Last Post: January 19th, 2006, 05:22 PM

Posting Permissions

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