Before anyone comments about security issues, don't bother.
Let's say I have an index.php
.
On this page there are various links pointing to 'home.php', but they all have different data stored in the href
attributes. E.g:
Link 1: 'home.php?data=1&country=uk'
Link 2: 'home.php?data=95&country=us'
Users could easily just type in www.website.com/home.php?data=*&country=*
and fill data in the URL to their liking.
What I am thinking is if I have a function that is ran when one of these links is clicked, which adds a value on to the URL before going to the destination. E.g:
Original link: www.website.com/home.php?data=1&country=uk
Clicked link: www.website.com/home.php?data=1&country=uk&verify=a8c9gj113
What I can not work out is how to change the href
data in HTML when clicking the link, before actually going to the destination.
My code is below (HTML is in a while loop pulling data from database)
<a href='home.php?data=". $results['id'] ."&country=". $results['country'] .' onclick='return verify();'>
Function:
function verify()
{
document.getElementById("verify").href="";
return true;
}
So for the HREF value in the function I am going to place the original URL (home.php?data=". $results['id'] ."&country=". $results['country'] .
) plus an extra value. How can I do this?
In a PHP echo when you are adding a value from a variable or etc you simply just end the echo with quotes, then add dots as shown below:
echo "I am the". $whatami ."person in the world";
Is there anything like this for JavaScript? When I paste that PHP URL into the JavaScript function in .href=""
, it is just going to fail because I am closing the quotes.
I hope people understand what I'm saying.
If there is a better way to do this please tell me.