StrongJoshua
StrongJoshua

Reputation: 995

PHP: Store PHP variable in page to use in POST

Currently I put a constant on my webpage using PHP which I then send, with Ajax, to my POST function. However, this leaves it susceptible to hacking (the user could change the variable with Firebug), so is there a way to store the variable in the PHP of the page and then access it later on, in the POST method (or is the GET variable of the page still available in the POST function, since that's where I get the variable from)?

Upvotes: 0

Views: 122

Answers (2)

tfrascaroli
tfrascaroli

Reputation: 1219

If you wish to store between successive calls from the same user use the follwing:

<?php
    session_start();
    $_SESSION["your variable/constant"] = yourvaule;

Now use the variable as needed, accessing it as $_SESSION["your variable/constant"]

Hope it helps, and it's what you're asking.

Upvotes: 0

Avinash Babu
Avinash Babu

Reputation: 6252

I think what you have wanted is to store the post value to use it later.

Here you would need to use $_SESSION

You can do it like

session_start();

// Save variables into session

$_SESSION['thevalue'] = $_POST['value'];

Upvotes: 2

Related Questions