# passing a calculated value to another web page

**URL:** <https://www.phphelp.com/t/passing-a-calculated-value-to-another-web-page/20929>\
**Category:** Beginners - Learning PHP\
**Created:** [August 25, 2013, 3:02am UTC](https://www.phphelp.com/t/passing-a-calculated-value-to-another-web-page/20929 "2013-08-25T03:02:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![milbra](https://www.phphelp.com/letter_avatar_proxy/v4/letter/m/ed8c4c/32.png) [@milbra](https://www.phphelp.com/u/milbra)\
**Post date:** [August 25, 2013, 3:02am UTC](https://www.phphelp.com/t/passing-a-calculated-value-to-another-web-page/20929/1 "2013-08-25T03:02:12Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![valandor062](https://www.phphelp.com/letter_avatar_proxy/v4/letter/v/ebca7d/32.png) [@valandor062](https://www.phphelp.com/u/valandor062)\
**Post date:** [August 25, 2013, 4:01am UTC](https://www.phphelp.com/t/passing-a-calculated-value-to-another-web-page/20929/2 "2013-08-25T04:01:41Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![tanzeelniazi](https://www.phphelp.com/user_avatar/www.phphelp.com/tanzeelniazi/32/410_2.png) [@tanzeelniazi](https://www.phphelp.com/u/tanzeelniazi)\
**Post date:** [August 25, 2013, 8:40am UTC](https://www.phphelp.com/t/passing-a-calculated-value-to-another-web-page/20929/3 "2013-08-25T08:40:58Z")

</div>

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

I also endorse Valandor062’s answer.

---

<div class="post-metadata">

**Author:** ![milbra](https://www.phphelp.com/letter_avatar_proxy/v4/letter/m/ed8c4c/32.png) [@milbra](https://www.phphelp.com/u/milbra)\
**Post date:** [August 29, 2013, 5:10pm UTC](https://www.phphelp.com/t/passing-a-calculated-value-to-another-web-page/20929/4 "2013-08-29T17:10:54Z")

</div>

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?

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

---

<div class="post-metadata">

**Author:** ![billthecat](https://www.phphelp.com/user_avatar/www.phphelp.com/billthecat/32/668_2.png) [@billthecat](https://www.phphelp.com/u/billthecat)\
**Post date:** [August 29, 2013, 6:41pm UTC](https://www.phphelp.com/t/passing-a-calculated-value-to-another-web-page/20929/5 "2013-08-29T18:41:38Z")

</div>

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=](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;  
[/php]

Hope that helps 🙂
