Jump to content

Search the Community

Showing results for tags 'cookie'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • W3Schools
    • General
    • Suggestions
    • Critiques
  • HTML Forums
    • HTML/XHTML
    • CSS
  • Browser Scripting
    • JavaScript
    • VBScript
  • Server Scripting
    • Web Servers
    • Version Control
    • SQL
    • ASP
    • PHP
    • .NET
    • ColdFusion
    • Java/JSP/J2EE
    • CGI
  • XML Forums
    • XML
    • XSLT/XSL-FO
    • Schema
    • Web Services
  • Multimedia
    • Multimedia
    • FLASH

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Languages

Found 16 results

  1. westman

    cookie coding

    Hi all, I am coding cookies for the first time and here is what I have. setcookie("username", $old_cookie, "1", "/", "", "", TRUE); setcookie("username", $new_cookie, strtotime( '+30 days' ), "/", "", "", TRUE); Is this the right way of resetting the value of one cookie? ps. I did read a lot on http://php.net/manual/en/function.setcookie.php but it is not clear.
  2. Gilbert

    Using document.cookie

    I'm just starting to use cookies for personalizing my website and I need a little clarification about the DOM. When a cookie is sent along with the request for a website, does it become available to the whole site (like every page you might load) or just to a specific page included in your website. I am planning on using the setcookie, getcookie and checkcookie functions from w3 - can I put them in any page of the website or do I have to use them from the initial page of my site? Any guidance would be appreciated.
  3. I was wondering if there is any way to set unique values to each cookie. I want to use these cookies on my website to see if the visitor has already visited my website once, but without asking any information from them. This way I want to store this unique value in my database each time someone opens my website, and I will be able to see if there have been - for example - 20 different visitors in the past month, or if the same person has visited my website 20 times. All my code is already written and working, I only need a way to set a different unique value to each cookie I set.
  4. I am trying to set a cookie when there is no cookie from my website found on the user's PC, but the following line of code doesn't work inside a function: $cookiename = "test"; $cookievalue = "tests"; setcookie($cookiename, $cookievalue, false, "/", "localhost"); It does work however if it is placed outside of the function. For exampe, the code above works, but the next code doesn't: $cookiename = "test"; $cookievalue = "tests"; function addCookie() { setcookie($cookiename, $cookievalue, false, "/", "localhost"); } addCookie();
  5. adrian.m123

    Deleting a cookie with value NULL

    I'm trying to erase completely a cookie that is set if a particular URL parameter is present.I've tried: function delete_cookie( name ) {document.cookie = name + '=; path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT;';} And it sets the cookie value to null but the cookie itself or at least the name of the cookie stays in the browser so that when the same URL is opened again, it will not update the cookie value from null to XXX nor is a second cookie with the URL value created.For the new cookie to be setup again I have to right-click on the cookie name (in Chrome) and choose delete. This way the cookie name and its value null are truly erased otherwise it stays with null value.How can I completely erase the cookie file and not just set it to null with javascript?I should mention that I also have the following function to grab the cookie from the URL parameter and to keep it from the first page until the final page (where it should be deleted after the cookie value is added as the value of an external URL parameter to an external within the final page). The second page will turn the original link into a session where the URL parameter is no longer visible.The link would be: http://xxxx.test.yyyy/index.html?myparameter[zzzzzz]=ddddd Here is the code for it:function URLparam(name) {return unescape((RegExp(name + '(?:[d+])?=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]);}$(document).ready(function () {if (URLparam("MyParameter") !== null && !get_cookie ("MyCookie")) {set_cookie ("MyCookie", URLparam("MyParameter"));} Any ideas?
  6. fintang

    Cookie dependent

    Hi, I have a button on my page and it links to a page that has a security notice on it, for the user to login the user has to agree that they've read this and then they click on the login in process. Is it possible if the user has read this previously(using cookies) that they are brought to the login page without showing the security page?The process is as follows:1. User clicks login.2. Depending on if the user has clicked "I have read this" the user will be brought to the login page..... if they have not read the message before then they will be brought to the security page.Hope this makes sense.Please any help would be greatly appreciated?ThanksDavid
  7. Hi everyone. I'm trying to write a cookie for a site I'm working on the displays a page until it triggers an onclick event. I have a section of the site that pulls up a disclaimer page with 2 options one that says I disagree and shoots you to the home page and one that triggers the cookie which if it's started in your browser will redirect you to the section you need to agree to in order to see. I've been able to get it to work upon visit, but I'm not having any luck with the on click event. I've been tweaking the script I found here --> http://www.javascrip...redirect-2.html I feel like I'm pretty close and have tried many onclick variations the following code I think is close. <a href="after-disclaimer-page.com" onClick="SetCookie('HasVisited')">I AGREE</a> Anyone have any ideas?
  8. CMS/Forum Session/cookie management and security, picking a good example. I am starting an opensource GPL forum project primarily for the sake of learning. I have been looking at the different implementations for user authentication and session management of different CMS and forum packages.Trying to go through and learn what is being done. Also wondering which makes for the best example of a good clean way to implement it.I would prefer to store the bare minimum cookies client side and keep most data in session variables server side.Unless there is a good reason to have another cookie or two, like if it somehow added additional security. SMF & Drupal makes use of the standard session_start(), and both also use database for session management.(more scalable) phpBB3 also uses the databse for session management, but does not use the standard "session_start()"it uses custom implementation using session_begin() , session_create() , session_kill() , session_gc() I like that Drupal only had the one session cookie, however it takes me much longer to follow the functions and understand what is happening with drupal code.In drupal a lot of things are generated like forms etc, using a single function, this is very clean as it reuses a lot of code, however I would rather learn from something easier to follow.I can always make the code more efficient afterwards. mybb seemed to set more cookies than the rest, and did not make use of the standard session_start(), I am unsure if it uses the db for session management. Right now I think I have it narrowed down to either SMF or PHPBB3, I am kinda leaning toward PHPBB because of a post I found: I read this post: https://www.phpbb.co...49840#p12949840 "Stealing a session id/key is not enough to get logged in. The IP must match to the extent defined in the ACP.Also, the browser user-agent must match (enabled by default). Additionally, you can have it check the x_forwarded_for value." I would think the extra checks like user-agent, IP, x_forwarded_for would help mitigate xss and sesion fixation.phpbb3 key function quotes:"Multiple keys may exist for each user representing different browsers or locations."I am curious if they limited the number of sessions per user, so that a malicious user cant intentionally create Tons of session keys on purpose. SMF may have the same checks, I am unsure. (I do not see IP or x_forwarded_for checks in the 'cookies and Sessions' admin section of smf, but they could be hardcoded.) Any insight or opinions on the subject are appreciated, or if you know of another opensource CMS or Forum that I should take a look at as a good example. at the moment I am leaning towards further studying the phpbb3 implementation and tryint to implement something similar.
  9. James_Parsons

    JavaScript escape function

    I was looking through one of my web dev books when I found a javascript function I just didn't get. it was used in a cookie that stored info about radio buttons chosen. the function is escape() and here is the line document.cookie="optFont=" +escape(fontChoice)+";expires="+expire.toUTCString(); can anyone tell me what this function does and some common uses
  10. rootKID

    my login does not working...

    yoyo w3s...im having a little trouble with my login page... here you can see the example: http://speed-scene.c...scene/login.php anyways, i allready knew about sessions and such, so i was thinking that it was time to expand my knowledge a little. so i was trying to make a login page that was using cookies to log me in, and while expanding, i was thinking that i could try it out on one of my projects on the following link i have allready given. but the trouble is that when im trying to login, then im just staying at the same page, and nofthing by then happends... here is all my login codes/pages im using: 1. bittorrent.php inside include folder from root (The functions im using to get the login thing to work...): function dbconn($autoclean = false){global $SS;if (!@mysql_connect($SS['mysql_host'], $SS['mysql_user'], $SS['mysql_pass'])){ switch (mysql_errno()) { case 1040: case 2002: if ($_SERVER['REQUEST_METHOD'] == "GET") die("<html><head><meta http-equiv='refresh' content=\"5 $_SERVER[REQUEST_URI]\"></head><body><table border='0' width='100%' height='100%'><tr><td><h3 align='center'>The server load is very high at the moment. Retrying, please wait...</h3></td></tr></table></body></html>"); else die("Too many users. Please press the Refresh button in your browser to retry."); default: die("[" . mysql_errno() . "] dbconn: mysql_connect: " . mysql_error()); }}mysql_select_db($SS['mysql_db']) or die('dbconn: mysql_select_db: ' . mysql_error());//mysql_query("SET NAMES utf8");mysql_set_charset('utf8');userlogin();if ($autoclean) register_shutdown_function("autoclean");} /*LOGIN FUNCTIONS*/function sqlesc($x) {return "'".mysql_real_escape_string($x)."'";}function mkglobal($vars) {if (!is_array($vars))$vars = explode(":", $vars);foreach ($vars as $v) {if (isset($_GET[$v])) $GLOBALS[$v] = unesc($_GET[$v]);elseif (isset($_POST[$v])) $GLOBALS[$v] = unesc($_POST[$v]);else return 0;}return 1;}function set_mycookie( $name, $value = "", $expires_in = 0, $sticky = 1 ){ global $SS; if ( $sticky == 1 ){ $expires = time() + 60*60*24*365;} else if ( $expires_in ) { $expires = time() + ( $expires_in * 86400 ); } else { $expires = FALSE; } $SS['cookie_domain'] = $SS['cookie_domain'] == "" ? "" : $SS['cookie_domain']; $SS['cookie_path'] = $SS['cookie_path'] == "" ? "/" : $SS['cookie_path']; if ( PHP_VERSION < 5.2 ) { if ( $SS['cookie_domain'] ) { @setcookie( $SS['cookie_prefix'].$name, $value, $expires, $SS['cookie_path'], $SS['cookie_domain'] . '; HttpOnly' ); } else { @setcookie( $SS['cookie_prefix'].$name, $value, $expires, $SS['cookie_path'] ); }}else{ @setcookie( $SS['cookie_prefix'].$name, $value, $expires, $SS['cookie_path'], $SS['cookie_domain'], NULL, TRUE );}}function logincookie($id, $passhash, $updatedb = 1, $expires = 0x7fffffff){set_mycookie( "uid", $id, $expires );set_mycookie( "pass", $passhash, $expires );if ($updatedb) @mysql_query("UPDATE users SET last_login = ".TIME_NOW." WHERE id = $id");}function logoutcookie() {set_mycookie('uid', '-1');set_mycookie('pass', '-1');}function loggedinorreturn() {global $CURUSER, $SS;if (!$CURUSER){ header("Location: {$SS['baseurl']}/login.php?returnto=" . urlencode($_SERVER["REQUEST_URI"])); exit();}}function get_mycookie($name){global $SS; if (isset($_COOKIE[$SS['cookie_prefix'].$name]) AND !empty($_COOKIE[$SS['cookie_prefix'].$name])) { return urldecode($_COOKIE[$SS['cookie_prefix'].$name]); } else { return FALSE; }}function userlogin() {global $SS;unset($GLOBALS["CURUSER"]);$ip = getip();$nip = ip2long($ip);require_once "cache/bans_cache.php";if(count($bans) > 0){foreach($bans as $k) { if($nip >= $k['first'] && $nip <= $k['last']) { header("HTTP/1.0 403 Forbidden"); print "<html><body><h1>403 Forbidden</h1>Unauthorized IP address. Please, piss off... you had your chance.</body></html>\n"; exit(); }}unset($bans);}if (!$SS['site_online'] || !get_mycookie('uid') || !get_mycookie('pass'))return;$id = 0 + get_mycookie('uid');if (!$id || strlen( get_mycookie('pass') ) != 32)return;$res = mysql_query("SELECT * FROM users WHERE id = $id AND enabled='yes' AND status = 'confirmed'");// or die(mysql_error());$row = mysql_fetch_assoc($res);if (!$row)return;if (get_mycookie('pass') !== $row["passhash"])return;mysql_query("UPDATE users SET last_access='" . TIME_NOW . "', ip=".sqlesc($ip)." WHERE id=" . $row["id"]);// or die(mysql_error());$row['ip'] = $ip;$GLOBALS["CURUSER"] = $row;}/*LOGIN FUNCTIONS*/ 2. this is my password_functions.php file inside include folder from root: <?phpfunction mksecret($len=5){ $salt = ''; for ( $i = 0; $i < $len; $i++ ) { $num = rand(33, 126); if ( $num == '92' ) { $num = 93; } $salt .= chr( $num ); } return $salt;} function make_passhash_login_key($len=60){ $pass = mksecret( $len ); return md5($pass);} function make_passhash($salt, $md5_once_password){ return md5( md5( $salt ) . $md5_once_password );} function make_password(){ $pass = ""; $unique_id = uniqid( mt_rand(), TRUE ); $prefix = mksecret(); $unique_id .= md5( $prefix ); usleep( mt_rand(15000,1000000) ); mt_srand( (double)microtime()*1000000 ); $new_uniqueid = uniqid( mt_rand(), TRUE ); $final_rand = md5( $unique_id.$new_uniqueid ); mt_srand(); for ($i = 0; $i < 15; $i++) { $pass .= $final_rand{ mt_rand(0, 31) }; } return $pass; }?> 3. this is my login.php file from root: <?phprequire_once("include/bittorrent.php");echo stdhead("Login");?> <form method="post" action="takelogin.php"><table class="login_table" align="center" border="1"><tr><td>Username</td><td><input type="text" name="username" id="username" size="35" /></td></tr><tr><td>Password</td><td><input type="password" name="password" id="password" size="35" /></td></tr><tr><td align="center" colspan="2"><input type="submit" name="login_submit" value="Login Now!" /></td></tr></table></form> <?phpecho stdfooter();?> 4. and at last, this is my takelogin.php file from root: <?phprequire_once 'include/bittorrent.php';require_once "include/password_functions.php";echo stdhead("Login");if (!mkglobal('username:password'))die();dbconn();$lang = array_merge(load_language('takelogin'));$res = mysql_query("SELECT id, passhash, secret, enabled FROM users WHERE username = " . sqlesc($username) . " AND status = 'confirmed'");$row = mysql_fetch_assoc($res);if (!$row)stderr($lang['tlogin_failed'], 'Username or password incorrect');if ($row['passhash'] != make_passhash($row['secret'], md5($password)))stderr($lang['tlogin_failed'], 'Username or password incorrect');if ($row['enabled'] == 'no')stderr($lang['tlogin_failed'], $lang['tlogin_disabled']);logincookie($row['id'], $row['passhash']);header("Location: {$SS['baseurl']}/index.php");echo stdfooter();?> and now to the big question, what the heck is wrong since i cannot login?... ideas where to check... it seems for my eye that i cannot see where to edit, since its all looking pretty well for both me and 1 other guys online i am coding with sometimes ... but the login does not work, so it is obviously that the codes does not either...but in anyways... i would be very much happy if anyone in here could tell me where to have my eyes on... thanks alot! ... PS: if wish to see the whole project, then you can use the following .FTP user to grand acces to the server and read the files, just in case you need more information.. HOST: blackbitt.comUSER: ftp_reader@blackbitt.comPASS: Reader1PORT: 21 bittorrent.php file is the main design to the whole site, and all my functions. in this way i have maked a Global Based design... Hoping you guys once more can guid me on to the right road again, thanks alot in advance! ...
  11. dalawh

    Cookies

    I notice that you can check if a cookie is set or retrieve the information if you knew the name, but what happens if the name was dynamic (changing for each person)? Is there no way to retrieve it? Should the name always be dynamic?
  12. dalawh

    PHP cookies vs JavaScript cookies

    Are they the same or are they different?
  13. dalawh

    Cookies

    I was looking at http://www.w3schools.com/js/js_cookies.asp and I was wondering if there was something more detailed on cookies. How do cookies look like? Are they just like a text in a document? If you look at the getCookie function, it only gets one line from the cookie, which I assume is because of the setCookie function only creates 1 line, but isn't a cookie normally larger or are cookies individually defined/created by the web designer and not the browser itself? What does "unescape(y)" do?
  14. flix_is_here22

    retrieve the cookie?

    hi, i so confused with retrieve the cookie when retrieve the cookie in the other file....i have some file....1. login.php -----> this file have a action form to checklogin.php2. checklogin.php -->cookie usrname to be set and the end of code i put header("location: home.php")3. home.php ---> menu of my website after user login. so i really confused when i retrieve the cookie usrname in the file home.php.....how to retrieve the cookie of usrname into home.php....??i has been try this code :echo $_POST["usrname"]; orecho $_COOKIE["usrname"];but both of this code isn't work..... :fool:any sugesstion??
  15. HrBingR

    Cookie Help

    Hello. I'm new to the W3Schools Forums, and I'm relatively new to web developing. I have a question. My website, www.universallinks.co.za, went live not long ago. I'm in the process of developing a mobile version of the website, but I have a small problem. If a user on a mobile device goes to my website, I wish to present them with the opportunity to switch to the main website. It's easy enough to do so, except I don't know how to use cookies. Could anyone on the forum assist me in this matter? My website is primarily coded in HTML, so I hope I've posted in the right section. I did search the forum, but found nothing on 'cookies'. Thank you.
  16. wiggout

    Saving Menu State

    I am trying to save the state of a tree menu by storing the name of the open section in a cookie, and then reading the cookie onload. It seems to be going to the href url before writing to the cookie. Below is my code and some examples of where the functions are used in my page. Thanks in advance for you help. <body id="body" onload="getMenuState()"> <a href="/" onclick="setMenuState('none');">Home</a> <li class="nav" onmouseover="mOvr1(this);" onmouseout="mOut1(this);" onclick="setMenuState('sectionLinks_1')"> <a href="/Security-Camera-Systems-s/19.htm" >Security Cameras</a></li> function setMenuState(targetId){ for(var i=1;i<=4;i++) {document.getElementById('sectionLinks_'+i).style.display="none";} {document.cookie="openMenu="+targetId;}}function getMenuState(){ var search = "openMenu="; if (document.cookie.length > 0) { offset = document.cookie.indexOf(search) // if cookie exists if (offset != -1) { offset += search.length // set index of beginning of value end = document.cookie.indexOf(";", offset); // set index of end of cookie value if (end == -1){end = document.cookie.length;} value = unescape(document.cookie.substring(offset, end)); if(value != "none"){document.getElementById(value).style.display="block";} } }}
×