![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
|
New Webmasters ask "How-To" questions here. This is where other fucking Webmasters help. |
|
Thread Tools |
![]() |
#1 |
Confirmed User
Industry Role:
Join Date: Apr 2011
Location: Paso Robles, CA
Posts: 127
|
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. |
![]() |
![]() ![]() ![]() ![]() |
![]() |
#2 |
Web Developer
Industry Role:
Join Date: Jan 2011
Location: UK
Posts: 264
|
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 ?> Code:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <input type="text" name="id" value="<?php echo $affid; ?>"> </form> Code:
<?php echo $affid; ?> Rob |
![]() |
![]() ![]() ![]() ![]() |
![]() |
#3 |
Confirmed User
Industry Role:
Join Date: Apr 2011
Location: Paso Robles, CA
Posts: 127
|
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. |
![]() |
![]() ![]() ![]() ![]() |
![]() |
#4 |
Web Developer
Industry Role:
Join Date: Jan 2011
Location: UK
Posts: 264
|
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 ?> Hope this helps. Please feel free to ask if you have any other questions Rob |
![]() |
![]() ![]() ![]() ![]() |
![]() |
#5 |
Confirmed User
Industry Role:
Join Date: Apr 2011
Location: Paso Robles, CA
Posts: 127
|
Then I would change the form action slightly as well, no?
changing from PHP Code:
PHP Code:
|
![]() |
![]() ![]() ![]() ![]() |
![]() |
#6 |
Web Developer
Industry Role:
Join Date: Jan 2011
Location: UK
Posts: 264
|
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 |
![]() |
![]() ![]() ![]() ![]() |
![]() |
#7 |
Confirmed User
Industry Role:
Join Date: May 2011
Location: Bedworth, United Kingdom
Posts: 1,022
|
hey robber great job man . even I also learnt from this . thanks from my side too.
__________________
Guaranteed Adult SEO Service- Just $275 per month |
![]() |
![]() ![]() ![]() ![]() |
![]() |
#8 |
Web Developer
Industry Role:
Join Date: Jan 2011
Location: UK
Posts: 264
|
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 ?> 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 ?> 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 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 ?> 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 ?> Then wherever you would like to insert the affiliate code put: Code:
<?php echo $affid; ?> 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 at 01:58 AM.. Reason: Just a few amendments, and ironing out what I meant |
![]() |
![]() ![]() ![]() ![]() |