Posts

Pure Javascript async post function , formdata, json object

var url = "https://www.example.com";  var myObject = new Object(); myObject.firstKey = "firstkey"; myObject.secondField = "secondfield";  var myJSON = JSON.stringify(myObj); var formData = new FormData(); formData.append("k",myJSON+"=,="); var ans = postData(url,formData); if(ans=="ok"){ doSth(); } async function postData(url,formData) {     try {       const response = await fetch(url, {         method: "POST",         body: formData,       });       const result = await response.text();                   return result;     } catch (error) {       console.error("Error:", error);     }       }

Php header.php , footer.php Example

header1.php  <?php ini_set ( 'display_errors' , 1 ); ini_set ( 'display_startup_errors' , 1 ); error_reporting (E_ALL); $lifespan = 18000 ; ini_set ( 'session.gc_maxlifetime' , $lifespan ); ini_set ( 'session.cookie_lifetime' , $lifespan ); session_start (); ? > <?php include 'db_con.php' ; ? > <?php global $basketCount ; $selectedLang = "en" ; if ( isset ( $_SESSION [ 'lang' ])){ $selectedLang = $_SESSION [ 'lang' ]; } $langFile = "language__" . $selectedLang . ".ini" ; $parsedFile = parse_ini_file ( $langFile ); if ( isset ( $_SESSION [ 'basketcount' ])){ $basketCount = $_SESSION [ 'basketcount' ]; } if ( isset ( $_SESSION [ "gid" ])){ } else { $_SESSION [ 'gid' ] = substr ( md5 ( rand ()), 0 , 10 ); } $ip = isset ( $_SERVER [ 'HTTP_CLIENT_IP' ]) ? $_SERVER [ 'HTTP_CLIENT