GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Webmaster Q & Fuckin' A (https://gfy.com/forumdisplay.php?f=27)
-   -   Appending links with PHP (https://gfy.com/showthread.php?t=1026867)

officemike 06-16-2011 03:06 PM

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.

robber 06-16-2011 03:27 PM

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

officemike 06-30-2011 06:14 PM

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.

robber 07-01-2011 10:34 AM

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

officemike 07-05-2011 03:48 PM

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 ?

robber 07-07-2011 09:53 AM

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

dc0ded 07-19-2011 03:51 PM

hey robber great job man . even I also learnt from this . thanks from my side too.

robber 07-20-2011 01:52 AM

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


All times are GMT -7. The time now is 05:25 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123