Driving me bonkers (simple PHP)

SpaceshipSpaceship
SpaceshipSpaceship
SpaceshipSpaceship
Watch

noswad

Established Member
Impact
1
Hello.

Is it possible to take the end of a link e.g. .com/?id=123 and insert the '123' into the into a field of a registration page using PHP so I can log which users have referred others.

Thanks.
 
Last edited:
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
It is both possible and easy. If you had x.com/page.php?id=xx and

PHP:
echo '<input type=hidden name=id value=' . $_GET['id'] . '>';

somewhere on page.php then you would have a hidden form element containing the id of the referer.
 
0
Close
Thanks v much! :hehe:
 
0
Close
Hi

I got this working at first by changing the code a little bit but for some reason I can't get it to work any more.

Could anyone help me please? Its driving me nuts.

David :'(

P.S. The field doesn't have to be hidden although I would prefer it to be :hehe:
 
Last edited:
0
Close
Merged your threads ;)

Really isn't that hard either.. and would suggest the same as xemiterx.

PHP:
<?php

$id = intval($_GET['id']);

echo '<input type="hidden" name="id" value="' . $id . '">';  

?>

What did you change? ^^ Should work just fine.
 
0
Close
Excellent thanks. One little problem though -

If register.php?id=[text] the form is submitting '0' but if the id=[numbers] it's submitting correctly.

Any clues?

Thanks again
 
Last edited:
0
Close
Ok, I was assuming the 'id' was just numerical, well, you could do the following:

PHP:
<?php

$id = trim($_GET['id']);

if(preg_match("/([^a-z0-9]+)/i", $id))
{
    die('Invalid ID');
}

echo '<input type="hidden" name="id" value="' . $id . '">';  

?>
 
0
Close
Thanks v much. V grateful.
 
0
Close
CatchedCatched

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Search: choose where to search from the All tab
Open the search at the top of any page. On the All tab, the list next to the search box lets you choose where to search: everything, all...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back