Jump to content

Recommended Posts

Posted

I'm trying to remeber the user's language with a cookie in PHP:

<?php

//Set language and remember with cookie

$lang = $_GET['lang'];

if ($lang==null)

{

$lang = $_COOKIE["lang"];

if ($lang==null) $lang = "lua";

}

setcookie("lang",$lang,time()+30*24*60*60);

?><!DOCTYPE html>

<html>

<head>

<title>Leadwerks Game Engine Documentation</title>

 

Here is a URL with the language specified to CPP:

http://www.leadwerks.com/learn.php?page=API-Reference_Object_Entity_SetPosition〈=cpp'>http://www.leadwerks.com/learn.php?page=API-Reference_Object_Entity_SetPosition〈=cpp

 

This URL does not specify any language, and will default to LUA:

http://www.leadwerks.com/learn.php?page=API-Reference_Object_Entity_SetPosition

 

However, if you click the first link then the second link, a cookie should remember your language selection and display CPP the second time. Why is this not working?

Let's build cool stuff and have fun. :)

Posted

I'm not getting a request to set a cookie when I visit that page. When a server wants to add a cookie to a users browser, the server will send a "Set-Cookie" header.

 

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie

 

A simple solution and one that I prefer is to use $_SESSION instead of cookie. That way the data is stored on the server instead of on the users browsers making it more secure.

 

Make sure to call session_start() when working with $_SESSION.

Posted

I got it working! You have to click on the Lua / CPP links in the documentation page, but it works. So if you just select C++ once, it will stay that way next time you open a page.

 

One step closer. :)

Let's build cool stuff and have fun. :)

Posted

How does asking a question about cookies equal I dislike something you made?

 

Well you're re-writing the documentation so I just assumed, why re-invent the wheel twice. :P

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...