Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #39753 > unrolled thread
| Started by | Daniele Ferrarese <daniele.seversrl@gmail.com> |
|---|---|
| First post | 2021-03-24 09:36 -0700 |
| Last post | 2021-03-28 06:26 -0700 |
| Articles | 4 on this page of 24 — 8 participants |
Back to article view | Back to comp.lang.javascript
Create cookie from ID of <a> tag Daniele Ferrarese <daniele.seversrl@gmail.com> - 2021-03-24 09:36 -0700
Re: Create cookie from ID of <a> tag The Natural Philosopher <tnp@invalid.invalid> - 2021-03-24 17:54 +0000
Re: Create cookie from ID of <a> tag Daniele Ferrarese <daniele.seversrl@gmail.com> - 2021-03-25 01:05 -0700
Re: Create cookie from ID of <a> tag The Natural Philosopher <tnp@invalid.invalid> - 2021-03-25 09:13 +0000
Re: Create cookie from ID of <a> tag Daniele Ferrarese <daniele.seversrl@gmail.com> - 2021-03-25 02:21 -0700
Re: Create cookie from ID of <a> tag Daniele Ferrarese <daniele.seversrl@gmail.com> - 2021-03-25 03:23 -0700
Re: Create cookie from ID of <a> tag Daniele <webmaster@appliserver.com> - 2021-03-26 09:19 +0100
Re: Create cookie from ID of <a> tag Daniele Ferrarese <daniele.seversrl@gmail.com> - 2021-03-26 01:57 -0700
Re: Create cookie from ID of <a> tag Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2021-03-26 17:33 +0100
Re: Create cookie from ID of <a> tag Jon Ribbens <jon+usenet@unequivocal.eu> - 2021-03-26 17:20 +0000
Re: Create cookie from ID of <a> tag Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2021-03-26 19:35 +0100
Re: Create cookie from ID of <a> tag Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2021-03-26 23:22 +0100
Re: Create cookie from ID of <a> tag "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2021-03-26 15:39 -0700
Re: Create cookie from ID of <a> tag Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2021-03-31 00:58 +0200
Re: Create cookie from ID of <a> tag "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2021-03-30 19:58 -0700
Re: Create cookie from ID of <a> tag Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2021-04-01 10:09 +0200
Re: Create cookie from ID of <a> tag "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2021-04-01 06:11 -0700
Re: Create cookie from ID of <a> tag Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2021-04-01 19:34 +0200
Re: Create cookie from ID of <a> tag The Natural Philosopher <tnp@invalid.invalid> - 2021-03-26 17:10 +0000
Re: Create cookie from ID of <a> tag Daniele <webmaster@appliserver.com> - 2021-03-27 12:16 +0100
Re: Create cookie from ID of <a> tag The Natural Philosopher <tnp@invalid.invalid> - 2021-03-27 13:25 +0000
Re: Create cookie from ID of <a> tag "Mark-" <nospam@mapson.xyz> - 2021-03-31 13:26 +0000
Re: Create cookie from ID of <a> tag Daniele <webmaster@appliserver.com> - 2021-03-27 12:08 +0100
Re: Create cookie from ID of <a> tag Man From a city with name Viljandi <ya12983@mail.com> - 2021-03-28 06:26 -0700
Page 2 of 2 — ← Prev page 1 [2]
| From | The Natural Philosopher <tnp@invalid.invalid> |
|---|---|
| Date | 2021-03-27 13:25 +0000 |
| Message-ID | <s3nbov$thr$1@dont-email.me> |
| In reply to | #39786 |
On 27/03/2021 11:16, Daniele wrote: > Il 26/03/2021 18:10, The Natural Philosopher ha scritto: >> On 26/03/2021 16:31, Thomas 'PointedEars' Lahn wrote: >>> Daniele wrote: >>> ^^^^^^^ >>> Please post using your real name (first name and last name suffice). >> Please refrain from silly monikers like 'pointed ears' > > No, I know PE (its digital personality at least) from long time. > He is a bit nitpicking and pedantic, but if you take from him "the good > parts" (cit.) he is a valuable contributor. > > So my advice is to listen at him, maybe avoiding accurately to debate > with him about his "recommendations"... > :-) yes. > Dan -- Climate Change: Socialism wearing a lab coat.
[toc] | [prev] | [next] | [standalone]
| From | "Mark-" <nospam@mapson.xyz> |
|---|---|
| Date | 2021-03-31 13:26 +0000 |
| Message-ID | <s41t9c$1g2e$1@gioia.aioe.org> |
| In reply to | #39786 |
Daniele wrote: > He is a bit nitpicking and pedantic... A "bit"; are you kidding.
[toc] | [prev] | [next] | [standalone]
| From | Daniele <webmaster@appliserver.com> |
|---|---|
| Date | 2021-03-27 12:08 +0100 |
| Message-ID | <s3n3nm$760$1@dont-email.me> |
| In reply to | #39768 |
Il 26/03/2021 17:31, Thomas 'PointedEars' Lahn ha scritto:
> Daniele wrote:
> ^^^^^^^
> Please post using your real name (first name and last name suffice).
>
Gosh, I chaged my ID string to meet your suggestions some time (years?) ago.
It seems that it is not enough, anyway. :-)
>> Hi, this is the code I use to manage cookies:
>>
>> function createCookie(name,value,days) {
>> if (days) {
>> var date = new Date();
>> date.setTime(date.getTime()+(days*24*60*60*1000));
>
> As we know the number of (milli)seconds per standard day,
>
> … + days * 864e5
>
> would be more efficient (if this way of moving a date value forward one day
> would be safe).
>
>> function readCookie(name) {
>> var nameEQ = name + "=";
>> var ca = document.cookie.split(';');
>> for(var i=0;i < ca.length;i++) {
>
> [“for” is not a function. Do not write it as if it were.]
>
> for (var i = 0, len = ca.length; i < len; ++i) {
>
>> var c = ca[i];
>> while (c.charAt(0)==' ') c = c.substring(1,c.length);
>
> Ouch.
>
> c = c.replace(/^ +/, '');
>
>> if (c.indexOf(nameEQ) == 0) return
> c.substring(nameEQ.length,c.length);
>
> The argument c.length is superfluous.
>
>> }
>> return null;
>
> The return value on failure should be “undefined” instead because the
> function returns a primitive (String) value, not an object value, if
> successful.
>
>> }
>
> That is *very* inefficient and error-prone. Consider this:
>
> function readCookie (name)
> {
> return (
> document.cookie.split(';')
> .ca.map((cookie) => cookie.split('='))
> .filter((cookie) => cookie[0] == name) || []
> )[0];
> }
>
> [without .filter(), this is useful as an approach to obtain *all*
> cookies in an easily processible data structure],
>
> or
>
> function readCookie (name)
> {
> /*
> * NOTE: Cookie names typically do not contain
> * RegExp special characters; otherwise those
> * need to be escaped.
> */
> return (document.cookie
> .match(new RegExp('(?:^|;)' + name + '=([^;]+)')) || [])[1];
> }
>
>
wow. Thank you Thomas.
Unfortunately, this use of "=>" is new to me.
I'll dig into it.
Dan
[toc] | [prev] | [next] | [standalone]
| From | Man From a city with name Viljandi <ya12983@mail.com> |
|---|---|
| Date | 2021-03-28 06:26 -0700 |
| Message-ID | <1bdeacc4-641b-4846-a5a8-dcbd94317aden@googlegroups.com> |
| In reply to | #39753 |
Why use JS for cookies ?
You can use php objects saving, which I have recently developed. or PHP sessions.
Php objects saving class:
==> data.php <==
<?php
class Dobj {
function getNameOfClass()
{
return static::class;
}
}
class Data {
var $dtables;
function gettime() {
return date("d.m.Y H:i:s");
}
function loadobjecttables() {
$dtables = array();
foreach (glob("*.dat") as $file) {
$path_parts = pathinfo($file);
if(!class_exists($path_parts['filename'])) {
continue;
}
$file1 = file_get_contents($file, true);
$dtables[] = unserialize($file1);
}
$this->dtables=$dtables;
}
function deleteotable($otabname) {
if (file_exists($otabname.".dat")) {
unlink($otabname.".dat");
}
$this->loadobjecttables();
}
function insertobject($obj) {
$this->loadobjecttables();
$oclass=$obj->getNameOfClass();
$tabls=$this->dtables;
$oarridx=-1;
for($i=0; $i<count($tabls); $i++) {
if($tabls[$i][0]->getNameOfClass()==$oclass) {
$oarridx=$i;
}
}
if($oarridx==-1) return false;
$tabls[$oarridx][]=$obj;
unlink($oclass.".dat");
$b=serialize($tabls[$oarridx]);
$fh = fopen($oclass.".dat", "a");
fwrite($fh, $b);
fclose($fh);
chmod($oclass.".dat", 0700);
}
function saveobjecttables() {
$tabls=$this->dtables;
for($i=0; $i<count($tabls); $i++) {
$oc=$tabls[$i][0]->getNameOfClass();
if (file_exists($oc.".dat")) {
unlink($oc.".dat");
}
$b=serialize($tabls[$i]);
$fh = fopen($oc.".dat", "a");
fwrite($fh, $b);
fclose($fh);
chmod($oc.".dat", 0700);
}
return true;
}
function saveobjecttable($objcl) {
$tabls=$this->dtables;
$obclindex=-1;
for($i=0; $i<count($tabls); $i++) {
if($tabls[$i][0]->getNameOfClass()==$objcl) {
$obclindex=$i;
break;
}
}
if (file_exists($objcl.".dat")) {
unlink($objcl.".dat");
}
$b=serialize($tabls[$obclindex]);
$fh = fopen($objcl.".dat", "a");
fwrite($fh, $b);
fclose($fh);
chmod($objcl.".dat", 0700);
return true;
}
function makearrayunique($array){
$duplicate_keys = array();
$tmp = array();
foreach ($array as $key => $val){
if (is_object($val))
$val = (array)$val;
if (!in_array($val, $tmp))
$tmp[] = $val;
else $duplicate_keys[] = $key;
}
foreach ($duplicate_keys as $key)
unset($array[$key]);
return $array;
}
function deleteduplicates() {
$ob=$this->dtables;
for($i=0; $i<count($ob); $i++) {
$o12=$this->makearrayunique($ob[$i]);
$ob[$i]=$o12;
}
$this->saveobjecttables();
}
function deleteduplicatescl($objcl) {
$ob=$this->dtables;
$obclindex=-1;
for($i=0; $i<count($ob); $i++) {
if($ob[$i][0]->getNameOfClass()==$objcl) {
$obclindex=$i;
break;
}
}
$o12=$this->makearrayunique($ob[$obclindex]);
$ob[$obclindex]=$o12;
$this->dtables=$ob;
$this->saveobjecttable($objcl);
}
function objectClassestoarray($objectA,
$objectB) {
$new_object = array();
foreach($objectA as $property => $value) {
$new_object[$property]=$value;
}
foreach($objectB as $property => $value) {
$new_object[$property]=$value;
}
return $new_object;
}
function query($query) {
$this->loadobjecttables();
$ovars=array();
$objects=$this->dtables;
for($i=0; $i<count($objects); $i++) {
$ovars[]=array_keys(get_object_vars($objects[$i][0]));
}
$mches=array();
$results=null;
$exitf=false;
for($i=0; $i<count($objects); $i++) {
if($exitf) break;
for($j=0; $j<count($ovars); $j++) {
if($exitf) break;
if(!class_exists($objects[$i][0]->getNameOfClass())) continue;
if(preg_match("/^get \* from ".$objects[$i][0]->getNameOfClass().";$/",$query)) {
$objectsList = [];
foreach ($objects[$i] as $obj) {
$objectsList[] = (array)$obj;
}
return $objectsList;
$exitf=true;
}
}
}
for($i=0; $i<count($objects); $i++) {
if($exitf) break;
for($j=0; $j<count($ovars); $j++) {
if($exitf) break;
if(!class_exists($objects[$i][0]->getNameOfClass())) continue;
if(preg_match("/^get ".$ovars[$i][$j]." from ".$objects[$i][0]->getNameOfClass().";$/",$query)) {
return array_column($objects[$i], $ovars[$i][$j]);
$exitf=true;
}
}
}
$outp=array();
for($i=0; $i<count($objects); $i++) {
if($exitf) break;
for($j=0; $j<count($ovars[$i]); $j++) {
if($exitf) break;
for($k=0; $k<count($objects); $k++) {
if($exitf) break;
for($l=0; $l<count($ovars[$k]); $l++) {
if($exitf) break;
if(!class_exists($objects[$i][0]->getNameOfClass())) continue;
if(!class_exists($objects[$k][0]->getNameOfClass())) continue;
if(preg_match("/^get \* from ".$objects[$i][0]->getNameOfClass()." join ".$objects[$k][0]->getNameOfClass().
" on \(".$objects[$i][0]->getNameOfClass()."\.".$ovars[$i][$j]."\=".$objects[$k][0]->getNameOfClass().
"\.".$ovars[$k][$l]."\);$/",$query)) {
for($ii=0; $ii<count($objects[$i]); $ii++) {
for($ii2=0; $ii2<count($objects[$k]);$ii2++) {
if($objects[$i][$ii]->{$ovars[$i][$j]}==$objects[$k][$ii2]->{$ovars[$k][$l]}) {
$oobj = $this->objectClassestoarray($objects[$i][$ii], $objects[$k][$ii2]);
$outp[]=$oobj;
}
}
}
$exitf=true;
}
}
}
}
}
for($k=0; $k<count($objects); $k++) {
if($exitf) break;
for($l=0; $l<count($ovars[$k]); $l++) {
if($exitf) break;
for($l2=0; $l2<count($ovars[$k]); $l2++) {
if($exitf) break;
if(!class_exists($objects[$k][0]->getNameOfClass()))
continue;
if(preg_match("/^get \* from ".$objects[$k][0]->getNameOfClass()." where ".$ovars[$k][$l]."\=(.*) and ".$ovars[$k][$l2]."\=(.*);$/",$query, $matches)) {
for($ii2=0;
$ii2<count($objects[$k]); $ii2++) {
if($objects[$k][$ii2]->{$ovars[$k][$l]}==$matches[1]&&$objects[$k][$ii2]->{$ovars[$k][$l2]}==$matches[2]) {
$oobj = (array)$objects[$k][$ii2];
$outp[]=$oobj;
}
}
$exitf=true;
}
}
}
}
for($k=0; $k<count($objects); $k++) {
if($exitf) break;
for($l=0; $l<count($ovars[$k]); $l++) {
if($exitf) break;
if(!class_exists($objects[$k][0]->getNameOfClass())) continue;
if(preg_match("/^get \* from ".$objects[$k][0]->getNameOfClass()." where ".$ovars[$k][$l]."\=(.*);$/",$query, $matches)) {
for($ii2=0; $ii2<count($objects[$k]); $ii2++) {
if($objects[$k][$ii2]->{$ovars[$k][$l]}==$matches[1]) {
$oobj = (array)$objects[$k][$ii2];
$outp[]=$oobj;
}
}
$exitf=true;
}
}
}
if(count($outp)>0) {
return $outp;
}
return $mches;
}
}
?>
With the best wishes,
Your all very good friend.
Daniele Ferrarese kirjutas kolmapäev, 24. märts 2021 kl 18:36:43 UTC+2:
> Hello, I'm a beginner with js. I was wondering if it was possible to create a cookie by taking the value from the ID of the <a> tag.
> Thanks for your help.
>
> Rgds Daniele
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.javascript
csiph-web