PHP Get variables in Javascript

  • March 25, 2013

You can get the PHP get variables from javascript using the following function:

            function $_GET(variable) {
                var query = window.location.search.substring(1);
                var vars = query.split("&");
                for (var i = 0; i < vars.length; i++) {
                    var pair = vars[i].split("=");
                    if (pair[0] == variable) {
                        return unescape(pair[1]);
                    }
                }
                return false;
            }

This will grab variables in the url such as http://coutblog.com?getVariable=value




No Comments


You can leave the first : )



Leave a Reply

Your email address will not be published. Required fields are marked *