NameSilo

Prompt user to input Affiliate ID# if omitted...

Spaceship Spaceship
Watch

Gene

Gene PimentelTop Member
Impact
485
I'm creating an affiliate site for a client, where their affiliates will each have a URL with their ID# like this: www.domain.com/12345.

If a prospect tries to go to just www.domain.com, I want that page to tell them that they need to include the ID# (www.*domain*.com/12345). Here is an example of what I'm taking about (I have no connection with this sample site): http://www.automaticbuilder.com

If you know how to create this or if you know where I can get the script, I'd appreciate hearing about it as soon as possible!

Thanks!
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Simple form stuff Gene, couldn't be easier, assuming I understood what you want. ;)

index.php:
Code:
<html>
<body>

<form action=checkID.php method=post>
<input type=text name=affiliateID maxlength=50>
<input type=submit name=submit value=Go>
</form>

</body>
</html>

And then you need checkID.php with this in:

Code:
<?php

$affiliateID = $_POST['affiliateID'];

if (is_numeric($affiliateID)) {

echo "AffiliateID: $affiliateID <br>Redirecting to www.*domain*.com/$affiliateID";
echo '<meta http-equiv="refresh" content="5;url=/$affiliateID">';
}
else {

echo "The AffiliateID you entered was invalid, please go back and try again. Redirecting to home page.";
echo '<meta http-equiv="refresh" content="5;url=index.php">';
}

?>

I hope that's what you were looking for. I'm assuming you wanted the AffiliateID to be numeric so I added a simple check to make sure it was, and if it isn't it redirects back to index.php. If it is, it goes ahead to www.*domain*.com/affiliateID.

If you need anything adding to it, let me know. :)
 
0
•••
That code won't work.

Change
echo '<meta http-equiv="refresh" content="5;url=/$affiliateID">';
To
echo '<meta http-equiv="refresh" content="5;url=/'.$affiliateID.'">';
 
0
•••
...and I don't trust is_numeric :red:

PHP:
<?php

$affiliateID = intval($_POST['affiliateID']);

if (!empty($affiliateID)) {
//rest of code here..
 
0
•••
Excellent! I haven't tried it yet, only because I need to clarify that the ID will NOT always be numerical. It can be alpha, numerical, or a combination. What needs to be changed in that case?

Edit: In fact, there does not have to be a verification of any kind -- it just needs to accept input and if the ID doesn't exist, that's okay. But if it does exist, it needs to bring the user to that page.
 
Last edited:
0
•••
Gene said:
Excellent! I haven't tried it yet, only because I need to clarify that the ID will NOT always be numerical. It can be alpha, numerical, or a combination. What needs to be changed in that case?

Edit: In fact, there does not have to be a verification of any kind -- it just needs to accept input and if the ID doesn't exist, that's okay. But if it does exist, it needs to bring the user to that page.
Make sure it contains, only #'s, letters? hmm...

PHP:
<?php

$affiliateID = trim(strip_tags($_POST['affiliateID'])); 

if(!preg_match('/[^a-z0-9]+/', $affiliateID))
{
  //woohoo
}
else
{
  //invalid
}

?>
Yeah Gene, just go ahead and edit on me before I post :lol:
 
0
•••
Yeah Gene, just go ahead and edit on me before I post :lol:

Sorry dude!

So how do I change that code so it doesn't do the verification thing?
 
0
•••
Ok,
PHP:
<?php

$affiliateID = trim(strip_tags($_POST['affiliateID']));

//Only checks if they left the field blank
if (!empty($affiliateID))
{
  echo 'AffiliateID: '.$affiliateID.'<br />Redirecting to www.*domain*.com/'.$affiliateID.'<br />
  <meta http-equiv="refresh" content="5;url=/'.$affiliateID.'">';
}
else
{
  echo 'Please enter your id.<br />
  <meta http-equiv="refresh" content="5;url=index.php">';
}

?>
 
0
•••
I would make a .htaccess to make everything after www.domain.com/ to go to index.php?id=w/e and then check it and if its good include the page or something and if its not say it's a bad code then show the form again.

I wouldn't want a 5 second meta refresh each time.. :|
 
0
•••
Dan Friedman said:
I would make a .htaccess to make everything after www.domain.com/ to go to index.php?id=w/e and then check it and if its good include the page or something and if its not say it's a bad code then show the form again.

I wouldn't want a 5 second meta refresh each time.. :|

I only understand about half of what you said... but what I'm doing is setting the refresh to "0" to avoid the delay.

Here's what I'm using, and it works perfectly...
PHP:
<?php

$affiliateID = trim(strip_tags($_POST['affiliateID']));

if (!empty($affiliateID))
{
  echo '<meta http-equiv="refresh" content="0;url=/'.$affiliateID.'">';
}
else
{
  echo 'Oops! You didnt enter anything. We are now redirecting you to the previous page.<br />
  <meta http-equiv="refresh" content="3;url=index.html">';
} 

?>

Now that I've tried it, I see that I need a way to redirect if the username doesn't exist at all. Any ideas?
 
0
•••
If you had
RewriteEngine on
RewriteRule ^(.*)? index.php?id=$1 [L]

When someone goes to domain.com/anything it would take them to domain.com/index.php?id=anything AND leave domain.com/anything in the address bar.

Then, I would make it check if it is a valid ID and if it is, show what ever you want it to and if it is not, show the form again.
 
0
•••
Dan Friedman said:
If you had
RewriteEngine on
RewriteRule ^(.*)? index.php?id=$1 [L]

When someone goes to domain.com/anything it would take them to domain.com/index.php?id=anything AND leave domain.com/anything in the address bar.

Then, I would make it check if it is a valid ID and if it is, show what ever you want it to and if it is not, show the form again.

I appreciate your help, but I have no idea how to do what you're saying. Thanks anyway!

Isn't there a simple way to modify the code I posted above so that it gets redirected to the original input page if the ID they type in doesn't exist?
 
0
•••
Gene to do that you need a database for your affiliates, which i'm assuming you already have. Have a table called "users" with one of the fields being called "ID" and this should work. It makes sure the user entered an ID, then it checks to see if that's in the database, and if it finds it, it goes ahead to domain.com/affiliateID.

Code:
<?php

$affiliateID = trim(strip_tags($_POST['affiliateID']));

if (!empty($affiliateID))
{

     $query  = "SELECT affiliateID FROM users WHERE ID='".$affiliateID."' ";
     $result = @mysql_query ($query);
     $num = mysql_num_rows ($result);

     if ($num > 0) {
     echo '<meta http-equiv="refresh" content="0;url=/'.$affiliateID.'">';
     } else {
     echo 'We couldn't find that affiliate ID in the database.';
     echo '<meta http-equiv="refresh" content="3;url=index.html">';
     }
}
else
{
echo 'Oops! You didnt enter anything. We are now redirecting you to the previous page.<br />
  <meta http-equiv="refresh" content="3;url=index.html">';
} 

?>
 
0
•••
Thanks a million guys... your help is more appreciated than you know. I am adding rep to all three of you and sending a token NP$ payment your way. Thank you!
 
0
•••
Dynadot โ€” .com TransferDynadot โ€” .com Transfer
Appraise.net
Domain Recover
NameMaxi - Your Domain Has Buyers
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back