Appending links with PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • officemike
    Confirmed User
    • Apr 2011
    • 127

    #1

    Appending links with PHP

    Fuck the paid applications out there that do this, I want to do this in-house, you know, for free:

    I am looking for a resource/documentation on using form action on my affiliate site that allows affiliates to enter their affiliate ID, and have a PHP function that can append the affiliate links with the user's ID as a cookie.

    I've googled it, yes, but I might as well google "help"--I get that many irrelevant results. I'm just on the cusp of figuring out with PHP, I just need a push in the right direction.
    OfficeMike
    Comms & Development

    PascalsSubSluts.com || Lacey Starr || LukeHardyXXX.com || EdPowers.com || Bruce Seven Films || SexyMomma || LatexPussycats || 3AM.XXX
  • robber
    Web Developer
    • Jan 2011
    • 264

    #2
    ok you want something like:

    Put this at the top of your page:
    Code:
    <?php session_start(); #<-- Must be first line
    if(!empty($_POST['id'])){$_SESSION['affid'] = $_POST['id'];} #<-- Sets the affiliate id
    {$affid = $_SESSION['affid'];} #<-- assign affiliate id
    if(empty($_SESSION['affid'])){$affid = "xxxxxx";} #<-- add a default value
     ?>
    when you have your input box have your form set like:
    Code:
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <input type="text" name="id" value="<?php echo $affid; ?>">
    </form>
    Then for each of your links just add the below code where ever you would like to have the affiliate id shown:
    Code:
    <?php echo $affid; ?>
    Hope this helps, if you need any more help please feel free to e-mail me: rob [at] foxydrop [dot] com or reply here

    Rob
    Last edited by robber; 06-16-2011, 02:32 PM.

    Comment

    • officemike
      Confirmed User
      • Apr 2011
      • 127

      #3
      Thanks Robber!

      Working this into my site. I forgot to mention it's a wordpress site, so perhaps a little more tricky working with the loop. My content is searchable, which puts the search results on a different page than the index. Can I place the code in my header, which appears on every page regardless if it's index, search, archive, etc...?


      Also, does this store the id to cookies? I would like to have the user's ID cookied, so it appends the link every time the user visits, without them having to enter the id every time.
      Last edited by officemike; 06-30-2011, 05:16 PM.
      OfficeMike
      Comms & Development

      PascalsSubSluts.com || Lacey Starr || LukeHardyXXX.com || EdPowers.com || Bruce Seven Films || SexyMomma || LatexPussycats || 3AM.XXX

      Comment

      • robber
        Web Developer
        • Jan 2011
        • 264

        #4
        OK then to have this set in a cookie like you have requested you would need to change the header script to being:

        Code:
        <?php 
        if(!empty($_POST['id'])){setcookie("affid",$_POST['id']);} #<-- Sets the affiliate id
        {$affid = $_COOKIE['affid'];} #<-- assign affiliate id
        if(empty($_COOKIE['affid'])){$affid = "xxxxxx";} #<-- add a default value
         ?>
        This will set a cookie for the user instead of storing the value within a session on the server

        Hope this helps. Please feel free to ask if you have any other questions

        Rob

        Comment

        • officemike
          Confirmed User
          • Apr 2011
          • 127

          #5
          Then I would change the form action slightly as well, no?
          changing from
          PHP Code:
          <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post";">
          to call a cookie instead...

          PHP Code:
          <form action="<?php echo $_COOKIE['affid']; ?>" method="post";">
          or do I still use $_server ?
          Last edited by officemike; 07-05-2011, 02:51 PM.
          OfficeMike
          Comms & Development

          PascalsSubSluts.com || Lacey Starr || LukeHardyXXX.com || EdPowers.com || Bruce Seven Films || SexyMomma || LatexPussycats || 3AM.XXX

          Comment

          • robber
            Web Developer
            • Jan 2011
            • 264

            #6
            No you leave everything else the same as the rest is what runs the form. if you need help integrating this please drop me an e-mail: [email protected] (replace the 0's with o's) and I will go through it with you and answer any other questions you have

            Kind Regards

            Rob

            Comment

            • dc0ded
              Confirmed User
              • May 2011
              • 1022

              #7
              hey robber great job man . even I also learnt from this . thanks from my side too.
              Guaranteed Adult SEO Service- Just $275 per month

              Comment

              • robber
                Web Developer
                • Jan 2011
                • 264

                #8
                Hi Guys,

                I've just looked back over what I wrote and I need to amend the header scripts just slightly. But I have also expanded on a few points raised above as well regarding processing and how to do this in a separate file

                ##################################################

                If you are storing your affiliate ID in a session, your header script should be:

                Code:
                <?php session_start(); #<-- Must be first line
                if(!empty($_POST['id'])){$_SESSION['affid'] = $_POST['id']; #<-- Sets the affiliate id
                $affid = $_SESSION['affid'];} #<-- assign affiliate id
                if(empty($_SESSION['affid'])){$affid = "xxxxxx";} #<-- add a default value
                 ?>
                If you are storing your affiliate ID in a cookie your header script should be:
                Code:
                <?php 
                if(!empty($_POST['id'])){setcookie("affid",$_POST['id']); #<-- Sets the affiliate id
                $affid = $_COOKIE['affid'];} #<-- assign affiliate id
                if(empty($_COOKIE['affid'])){$affid = "xxxxxx";} #<-- add a default value
                 ?>
                The rest should stay the same, so where you want to have your input box to insert your affiliate id put in:

                Code:
                <form action="<?php 
                echo $_SERVER['PHP_SELF']; # This will loop round to the same page, if you have a specific page you would like to direct to, just replace this whole php tag with the url/link to the page eg. "afflink.php"
                 ?>" method="post">
                <input type="text" name="id" value="<?php echo $affid; ?>">
                </form>
                If you want to process your link in an individual file your individual file should look like (You still need to have the header script in place to enable this to work):

                ### If Using Sessions ###
                Code:
                <?php
                session_start(); #<-- Must be first line
                if(!empty($_POST['id'])){$_SESSION['affid'] = $_POST['id']; #<-- Sets the affiliate id
                header("location: #File name here#"); #put in the file name eg. index.php
                exit(); #This will stop the script processing any further
                ?>
                ### If Using Cookies ###
                Code:
                <?php
                if(!empty($_POST['id'])){setcookie("affid",$_POST['id']); #<-- Sets the affiliate id
                header("location: #File name here#"); #put in the file name eg. index.php
                exit(); #This will stop the script processing any further
                ?>
                If you wanted to have a different file (one which is showing content) to be the page the user goes to after inserting their code, then just put the link in the form tags (as described above) and make sure that file has the header script in it and everything will work automatically.

                Then wherever you would like to insert the affiliate code put:
                Code:
                <?php echo $affid; ?>
                I hope this works for you, and it has covered most amendments and basic additional options for how you process the affiliate code on your site.

                If you are storing your affiliate ID in a database, please contact me and I will help you write the code as every database is different in design and naming and so I wouldn't be able to cover that in this tutorial. Please send help requests to: [email protected] (please replace the 0's for o's)

                Rob
                Last edited by robber; 07-20-2011, 12:58 AM. Reason: Just a few amendments, and ironing out what I meant

                Comment

                Working...