JayVee Posted November 25, 2008 Share Posted November 25, 2008 How would I go about rewriting this php in javascript? Its a simple cookie check with a redirect based on cookie value. else if (!isset($_COOKIE['legal'])) { header("Location: /index.php"); } else if($_COOKIE['legal'] == "no"){ header("Location: /index.php"); } Quote Link to comment Share on other sites More sharing options...
shutat Posted November 27, 2008 Share Posted November 27, 2008 if(document.cookie.length > 0 && document.cookie.substr(0, document.cookie.indexOf("=")) == cname) { if(document.cookie.substr(document.cookie.indexOf("=") + 1) == "no") { location.href = "index.php"; } else { // cookie data was something other than no } } else { location.href = "index.php"; // cookie wasn't set } I *think* that would do assuming the cookie format is just cname=no. Things to lookout for are indexOf is case sensitive, and it returns -1 if the match string isn't found. HTH Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.