i am presently passing the value of a variable to a php file using GET after data has been inserted to the database. ex= $firstname = $_POST["firstname"]; if(!$sqlconnection) { echo "error message"; } else { header("Location: thankyou.php?firstnameis=$firstname"); } how can i send the value of $firstname using POST instead of GET as the value is presently appearing in the address bar. ideally i would like using POST. NOTE = please suggest techniques that does NOT involve javascript in order to pass $firstname using POST method, as i have done the entire validations using php and i have assumed that user has javascript turned off. please advice. thanks.
You can have this - <form action="thankyou.php" method="post"> <input type="hidden" name="firstnameis" value="$firstname" /> </form> I'm not sure if there's a better method.
using php sessions session_start(); if(!$sqlconnection) { echo "error message"; } else { $_SESSION['firstname'] = $_POST['firstname']; header("Location: thankyou.php"); } Code (markup): on thankyou.php print $_SESSION['firstname']; Code (markup): $_SESSION data is stored on the server side.
thanks for letting me know. i have used session and it works without adding the variable name and value in the url. just wanted to confirm what i am doing is correct. i have 2 files a) form.php which gathers information entered in the form and b) thankyou.php which extracts the value of firstname store in form.php as $fname and displays this $fname and a thankyou message. code in form.php ============================================================================== session_start(); // AS THE VERY FIRST LINE FOLLOWED BY session_register("firstnameis"); $fname = $_POST["fname"]; $_SESSION['firstnameis'] = $fname; // SOMEWHERE IN BETWEEN THE CODE ============================================================================== code in thankyou.php ============================================================================== session_start(); // AS THE VERY FIRST LINE Dear <?php echo $_SESSION['firstnameis']; ?> thank you for registering etc... ============================================================================== 1. do i need to destroy or unregister the session variable in thankyou.php and if so can i write that unregister statement after displaying <?php echo $_SESSION['firstnameis']; ?> please advice. thanks.
Well, if you're not going to use that variable anymore then you can empty your $_SESSION to prevent abuse. Try this: unset($_SESSION); $_SESSION = array(); PHP: That will do. You would place this snippet right after this: <?php echo $_SESSION['firstnameis']; ?>
if you were only going to use that variable of first name once..why did you bother making it a SESSION at all? just use method="post" instead of method="get" in your <form> POST hides it , GET puts it into the address bar as a string youre going way out of your way with SESSIONS and session unsets() etc and why dont you just $_POST all that information to the same page ..so that you dont have to create a new page. $_POST will always post to the next page called. Whether its the same page, or another page. The only time it could have problems is when youre dealing with HTTPS and security that strips all incoming or outgoing data depending on its set up. but for what youre doing , just use a <form method="post" action="same-page-your-form-is-on.php"> but dont name it "same-page-your-form-is-on.php Just name it with your form page's name.