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.

PHP Url rewriter - Why is this not working?

Discussion in 'PHP' started by AzzidReign, Sep 28, 2015.

  1. #1
    I'm in need of some help with this code I'm trying to work with and the rewrite isn't working. I want to understand it further and possibly improve upon it.

    I'm wanting to take a URL like:
    http://www.newegg.com/Product/Product.aspx?Item=N82E16817182351&cm_sp=Homepage_FDD-_-P1_17-182-351-_-09282015
    Code (markup):
    And convert it to my commission junction (cj.com) link. It isn't working and since I'm not experienced with any coding language, I'm running into a road block. I have it working for ebay and amazon, just not cj and another affiliate network. What I have for newegg is:

      protected $_find = array(
        '~http?://([a-z\.]+\.)?newegg\.([a-z\.]+)/.*~', // NewEgg
    
      protected $_replace = array(
        '<a href="http://www.anrdoezrs.net/links/7880220/type/dlg/{0}" rel="nofollow external" title="NewEgg" target="_blank">[NAME]</a>', // Newegg
    
    Code (markup):
    I've tried different instances of that code like:
    '<a href="http://www.anrdoezrs.net/links/7880220/type/dlg/?url={0}" rel="nofollow external" title="NewEgg" target="_blank">[NAME]</a>', // Newegg
    '<a href="http://www.anrdoezrs.net/links/7880220/type/dlg/&url={0}" rel="nofollow external" title="NewEgg" target="_blank">[NAME]</a>', // Newegg
    Code (markup):
    All of which output the same code that I've put in the file without appending the actual URL to it. The URL to the above example should look like:
    http://www.anrdoezrs.net/links/7880220/type/dlg/http://www.newegg.com/Product/Product.aspx?Item=N82E16817182351&cm_sp=Homepage_FDD-_-P1_17-182-351-_-09282015
    Code (markup):
    Where on my site, it looks like (or something similar with the examples listed above):
    http://www.anrdoezrs.net/links/7880220/type/dlg/{0}
    Code (markup):
    Can anyone see what I'm doing wrong here?
     
    AzzidReign, Sep 28, 2015 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    Seems you're doing a lot of work for little gain. Since you're doing this particular thing for links containing Newegg only, you can just check the original url/string if it contains newegg, then put it on the end of your link. No need for regexes
     
    PoPSiCLe, Sep 28, 2015 IP
  3. AzzidReign

    AzzidReign Well-Known Member

    Messages:
    167
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    120
    #3
    That would be a few thousand links, I think a rewriter is more appropriate.
     
    AzzidReign, Sep 28, 2015 IP
  4. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #4
    Uhm, are you dense? I didn't say "do it manually", I said "don't use a regex". I'm on my phone, else I'd give you some examples, but look up the strpos function.
    Something like
    
    if (strpos('newegg', $original_url)) {
      echo $yoururl.$original_url;
    }
    
    Code (markup):
     
    PoPSiCLe, Sep 28, 2015 IP
  5. AzzidReign

    AzzidReign Well-Known Member

    Messages:
    167
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    120
    #5
    Sorry if I offended you. Yes, I'm a bit dense when it comes to coding. This is not something I do. I look at code and "hack" it so to speak. This is from a discontinued addon for xenforo. I'm using it this way because it is a modified bbcode file, which all url's are converted to bbcode on the site. I got it figured out, just needed to add a $ in front of the {0}. The next step would be to actually mask the url's similar to what slickdeals.net does so it is much harder to strip out the affiliate link. I have a few guides I'm looking at but I'm not sure how to implement it. If you have any ideas, I would greatly appreciate your help. Thanks for responding.
     
    AzzidReign, Sep 30, 2015 IP
  6. AzzidReign

    AzzidReign Well-Known Member

    Messages:
    167
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    120
    #6
    To add further, I'm thinking that second bit of code:
      protected $_replace = array(
        '<a href="http://www.anrdoezrs.net/links/7880220/type/dlg/{0}" rel="nofollow external" title="NewEgg" target="_blank">[NAME]</a>', // Newegg
    Code (markup):
    I think I need to replace that with "mysite.com/referral/newegg" and in the newegg folder, have a php file that will forward the affiliate URL along with it. The only thing I'm having a tough time with is, how do I append the affiliate link in there. So in the case of newegg, I need to make the link look like:
    http://www.anrdoezrs.net/links/7880220/type/dlg/http://newegg.com/Product/Product.aspx?Item=N82E16817182351&cm_sp=Homepage_FDD-_-P1_17-182-351-_-09282015
    Code (markup):
    Again, I'm not a coder, but it looks like I need to do something where I have {affiliate url}{product url}...

    Like on slickdeals, they have:
    http://slickdeals.net/?pno=164578&lno=1&trd=Newegg%2Bcom&afsrc=1
    Code (markup):
    But when you click the link it looks like this in the url bar:
    http://slickdeals.net/?pno=164578&lno=1&trd=Newegg%2Bcom&afsrc=1&csSid=ef3b16d467d711e58d754ad7379d63b10000
    Code (markup):
    That shows up when they are on the front page for some reason but in the thread, the url from the member looks like:
    http://slickdeals.net/?sdtid=8135360&sdop=1&sdpid=78486140&sdfid=9&lno=1&trd=ZyXEL+AV500+Powerline+w+N300+Wir&pv=&au=&u2=http%3A%2F%2Fwww.newegg.com%2FProduct%2FProduct.aspx%3FItem%3D0XP-0009-00037
    Code (markup):
    It seems converting to the URL that is posted by members may be the easiest route since it seems like they do multiple redirects when it reaches the frontpage deals.

    After posting all of this, I'm completely lost in the direction I need to go lol
     
    AzzidReign, Sep 30, 2015 IP