imprint
For lazy phpers, with this function you can read cookies and get parameters in javascript in php style.
(I use php tags to highlight the code)
Example
<?php
populateRequest();
if( $_COOKIE['sid'] ) {
// do something
}
if( $_GET['cmd'] == 'login' ) {
// do something
}
?>
<?php
function populateRequest(){
String.prototype.trim = function(){
return this.replace(/^s+|s+$/, '');
}
cookies = document.cookie.split(';');
window.$_COOKIE = new Object();
for(var i = 0; i < cookies.length; i++){
curentCookie = cookies[i];
var ckv = curentCookie.split('=');
var k = ckv[0];
var v = ckv[1];
if( k && v ){
k = k.trim();
$_COOKIE[k] = v;
}
}
var query = location.search.replace('?', '');
params = query.split('&');
window.$_GET = new Object();
for(var i = 0; i < params.length; i++){
curentParam = params[i];
var ckv = curentParam.split('=');
var k = ckv[0];
var v = ckv[1];
if( k && v ){
k = k.trim();
$_GET[k] = v;
}
}
}
?>
Recent comments
49 weeks 5 days ago
1 year 6 weeks ago
1 year 10 weeks ago
1 year 33 weeks ago
1 year 37 weeks ago
1 year 37 weeks ago
1 year 44 weeks ago
1 year 44 weeks ago
1 year 44 weeks ago
1 year 44 weeks ago