I know there are a few ways to pass a variable to another page for a form. But is there any secure way to pass the variable to another page?
POST
First form in the page
$firstName= 'Sarah';
$lastName = 'Lim';
$name = $firstName.' '.$lastName;
<form id="Staff" name="Staff" method="post" action="nextpage.php" enctype="multipart/form-data">
<input name="name" type="text" id="name" value="<?php echo $name?>"/>
<input type="submit" name="submit" value="Submit">
</form>
Passing variable to nextpage.php
$StudName = $_POST['name'];
$split = preg_split('/[ \.]/', $StudName);
echo $split[0].$split[1];
In this case, I must use session to pass the variable to nextpage.php. Is there any other more secured way or neater way? As if I have alot of fields in a form, there would be alot of “$_POST[‘…’]” in my second page.
The only secure way I can think of is to use https, if you’re looking for neater code you could do something like $p = $_POST; which will let you do echo $p[‘blah’]; for example.