0

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)?

3
  • Sounds like $_SESSION... Commented Sep 29, 2014 at 11:49
  • 1
    If your variable is not changeable on the front end, there's no point passing it from there; just have it available in your script as a php variable. If this isn't what you mean, it might be worth rewording your question to be more specific. Commented Sep 29, 2014 at 11:50
  • there seems to be no need to store it in the browser anyways, so shy not declare it in the php script directly? Commented Sep 29, 2014 at 11:51

2 Answers 2

2

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'];
Sign up to request clarification or add additional context in comments.

1 Comment

I was thinking of that, I just wasn't sure if it's the best choice.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.