Thursday, May 16, 2019

Redirect a page with variable in PHP with POST method

When a form submit I want to redirect to another page with some variable in the POST method.

We can't redirect page with post values in PHP directly.
In that case, there are several other options we can use. Here is one of them.


If we can use javascript as most sites are doing.


 we can do it as below.

<form name='fr' action='redirectpage.php' method='POST'>
      <input type='hidden' name='var1' value='val1'>
      <input type='hidden' name='var2' value='val2'>
</form>

<script type='text/javascript'>
     document.fr.submit();
</script>

This will post all variables to redirectpage.php.

I hope this will help you.

Thursday, May 2, 2019

Dynamic PHP variable


PHP allows you to use dynamic variable names, called variable variables. You can name a variable with the value stored in another variable. That is, one variable contains the name of another variable.


$Bangladesh = 147570;
$dhaka = 11500;
$cityname = "Bangladesh";
echo "The size of $cityname is ${$cityname}";
$cityname = "dhaka";
echo "The size of $cityname is ${$cityname}";
The output from this code is
The size of Bangladesh is 147570
The size of dhaka is 11500

Ref: https://www.dummies.com/programming/php/how-to-use-php-variable-variables/

Total Pageviews