@public #get #parmeter #url #javascript #js #jquery

how to grab URL GET parameters with Javascript

<div class="content">
  <p>Lorem Ipsum Anything</p>
  <script type="text/javascript">
    if(window.location.href.match(/arg=testA/)){
      document.write('<button name="button">Click me</button>');
    }elseif(window.location.href.match(/arg=TestB/)){
      document.write('<button name="button">Click me now!</button>');
    }else{
      document.write('<button name="button">Show me</button>');
    }
    /* Wobei in der match() Anweisung 
    ** ein beliebiges RegEx enthalten 
    ** sein kann.
    */
  </script>
  <p>Lorem Ipsum Anything</p>
</div>

How to transfer an Array over URL GET Parameters

<?php
/* array_over_get.php */
$image_arr=array("1.jpg","2.jpg","3.jpg","4.jpg","5.jpg","6.jpg");
$serial_arr=urlencode(base64_encode(serialize($image_arr)));

echo '<img src="process_images.php?arr='.$serial_arr.'" alt="stacked image"/>';
?>


<?php
/* process_images.php */
$image_arr=unserialize(base64_decode(urldecode($_GET['arr'])));

foreach($image_arr as $value){
   /* do anything here 
    * just as an example
    * https://gist.github.com/vdite/30644e28301916789ff5
    */
}
?>

Why use of base64 encoding? URLencoding on a string is a waste of space and you only have 4k. http://stackoverflow.com/a/8594760/2099411

BUT, base64 encode may have +=/ characters, that have to be translated with urlencode mehr Infos: http://mizine.de/html/array-ueber-get-url-parameter-uebergeben/

@public #array #get #parameter #serialize #php

Projects

Tags

Capsule Servers

Lost connection to server.