简体   繁体   中英

Best idea to pass variables from a href link

I have a href link, and I would like to pass some variables without using them in a link, what is the best idea?

<a href="Files/download.php?file=fileName">Click</a>

I would like to get these variables into my download.php page to update them into my database table:

timestamp
downloads
hits
views

Thanks in advance

<a href="Files/download.php?file=fileName" >Click</a>

Its all depend on your situation how to do it because there are lots of ways to do this

1) if you dont want to show the parameters to user, then you can encrypt them & add them in URL. 2) if you dont want parameters in URL, then you can create hidden input tags for all parameters & then using POST method submit that form on HREF click or store the values in session

<form id='hidden_form' action='Files/download.php'>
<input type='hidden' name='timestamp' value='some value' >
<input type='hidden' name='downloads' value='some value' >
<input type='hidden' name='hits' value='some value' >
<input type='hidden' name='views' value='some value' >

$_SESSION['timestamp']  = '<some value>';
$_SESSION['downloads']  = '<some value>';
$_SESSION['hits']   = '<some value>';
$_SESSION['views']  = '<some value>';

Using a link, you don't have much flexibility. You can really only pass them through the url.

You could do more however if this was a form, and these variables were passed as POST data. Then they would be hidden to the user and not present in the url. You could use hidden inputs:

<input type='hidden' name='myVariable' value='5' />

You could also store them in a $_SESSION but it's difficult to say what's best for your situation without context.

如果要使用href链接,请使用以下内容。

<a href="Files/download.php?file=fileName&timestamp=value&downloads=value&hits=value&views=value">Click</a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM