obinoob
obinoob

Reputation: 657

Read input type hidden value

Is it possible to read the value right on load? I suspect not.

<!DOCTYPE html>
<html>
    <head>
        <title>Some test</title>
    </head>
    <body>
        <form method="POST">
        <input type="hidden" name="token" value="<?php echo sha1("text")?>" >
        </form>
        <?php
        echo $_POST['token'];
        ?>
    </body>
</html>

Let's say I want to send some values generated by php like so:

<a href="url + page?options=1&token=sasadasdasda878asd7as8d7a"> 

Is there an option to get the token without passing it by URL (using get)?

Upvotes: 0

Views: 7756

Answers (2)

nimlhug
nimlhug

Reputation: 121

You can also use $_SESSION, since it's stored on server-side.

Upvotes: 0

Quentin
Quentin

Reputation: 943516

$_POST will be populated with the data sent by the browser.

If you have a form in the page, then the data submitted by the form will only be sent by the browser when the browser submits the form, it won't be submitted when the page is initially loaded since:

  • The page will probably be loaded via a GET request, not a POST request
  • The browser won't have the data in the form until after it receives the page, so it can't submit that data in the request for the page.

Upvotes: 2

Related Questions