httpSetResponseCookie | Multi Theft Auto: Wiki Skip to content

httpSetResponseCookie

Client-side
Server-side
Shared

Manual Review Required

Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.


This function sets the value for the specified HTTP cookie of the current HTML page.

Syntax

bool httpSetResponseCookie ( string cookieName, string cookieValue )
Required Arguments
  • cookieName: MISSING_PARAM_DESC
  • cookieValue: MISSING_PARAM_DESC

Returns

  • bool: value

Returns true if the cookie value was set successfully, false otherwise.

Code Examples

shared

This example is going to get the current users account name and save their name to a cookie.

<* local accName = getAccountName(user)
if not accName then return end
httpSetResponseCookie("userName",accName) *>
<!DOCTYPE html>
<html>
<body onLoad="getAcc();">
Your Account Name is: <span id="accnam"></span>
<script>
//getCookie function from w3schools.com
function getCookie(c_name){
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++){
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==c_name)
return unescape(y);
}
}
function getAcc(){
var acc = document.getElementById("accnam");
var name = getCookie("userName");
if(!name || name!="")
acc.innerHTML = name;
else
acc.innerHTML = "Could not get your account name!";
}
</script>
</body>
</html>