passing a calculated value to another web page

Hi everyone, I’m need to pass a random number I generated to another web page. All the examples I’ve seen are passing the variable’s value, which I don’t know.

Example… action="http://page-1.php?random=8423"

I’ve seen where you can pass a value thru a URL, which would work except I know the value.
My random number variable is $random.

Can someone please offer suggestions or tell me if my idea is completely wrong?

I’m not 100% certain if I understand your question or if my suggested solution would work. I’m not able to use my testing environment as or right now.

If you are storing the numeric value inside the variable $random then you may want to try

action="http://page-1.php?random=<?php echo $random ?>"

Same is true for me, I didn’t get your question :’(

I also endorse Valandor062’s answer.

I’m sorry it took so long to respond and that I wasn’t very clear expressing my question, but you gave me the answer I needed. I didn’t realize I could put php in the action statement.

Can you put any php code there? Could I do something like this?

action=“http://page-1.php?random=<?php $random=substr(number_format(time() * rand(),0,'',''),0,8); ?>”

Hi, yes you can put whatever you like there… but your format is a little off. Try it this way:
[php]action=“http://page-1.php?random=<?php substr(number_format(time() * rand(),0,'',''),0,8); ?>”[/php]

valandor062 had the variable $random in the url like that because it allows you to format things more cleanly, and you can use the variables elsewhere in your code. For example:

[php]$random = substr(number_format(time() * rand(),0,’’,’’),0,8);
// And your URL now is
action=“http://page-1.php?random=<?php echo $random; ?>”>Link Text

// I still want to use the $random variable, for example set it to a session to use on other pages
$_SESSION[‘random’] = $random;

Hope that helps :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service