Software development, photography, jokes, ....


noyb-logo

Sites by me

 
sds82-logo
tas-logoTransportation Administration System
snoezelkussen-logo-kleinstSnoezelen Pillows for Dementia
ikzoekeenbegeleider-logoBegeleiders voor gehandicapten
Laat uw hond het jaarlijkse vuurwerk overwinnen
Betuweroute en Kunst
logo 50x50Hey Vos! Je eigen naam@vos.net emailadres?
Kunst in huis? Nicole Karrèr maakt echt bijzonder mooie dingen
nettylogo2Kunst in huis? Netty Franssen maakt ook bijzonder mooie dingen

Hosting Favorites

 
ANU Internet Services
Netim
GoDaddy
XEL Media

Blogroll

 
Bomenstichting
Google Translate
PHP
MySQL
jQuery
jQuery UI
YourHead Stacks API
Favicon Generator.
Password Generator.
Check HTTPS problems





Categories

Archives

Marc's Place


 

Photo-blog


Alle getoonde foto's zijn (c) MHE Vos, Nederland.

All shown photo's are (c) MHE Vos, Netherlands.


Below blog is created with the Blogspot.stack using the Categories-filter.

Easiest star-rating code for PHP

 Permalink
I have added a how-to to make a simple and easy star-rating for whatever you would like to add a rating-possibility to...
You need a MySQL database, or some other data source, jQuery and PHP for this example.
Rating

Copy DOM content to the clipboard with pure Javascript

 Permalink
Of all the tips on the internet on how to copy data from a DOM element to the clipboard, I compiled my own function(s).

The examples below are to copy the 'href'-part of  a link to an RSS feed to the clipboard.

1. By class name, use the first found element
function copyToClipboardCN(element, attr) {
 x = document.getElementsByClassName(element);
 if(x !== undefined && x !== null && x[0] !== undefined) {
  var textarea = document.createElement("textarea");
  document.body.appendChild(textarea);
  textarea.value = x[0][attr];
  textarea.select();
  var status = document.execCommand('copy');
  textarea.remove();
 }
}

2. By id
function copyToClipboardID(element, attr) {
 x = document.getElementById(element);
 if(x !== undefined && x !== null) {
  var textarea = document.createElement("textarea");
  document.body.appendChild(textarea);
  textarea.value = x[attr];
  textarea.select();
  var status = document.execCommand('copy');
  textarea.remove();
 }
}

RSS feed link example with a class and an ID, using FontAwesome icons :

<a class="blog-rss-link" href="https://macvos.blogspot.com/feeds/posts/default" rel="alternate" target="_blank" title="RSS Feed" type="application/rss+xml"><i class="fa fa-rss"> RSS Feed <i class="fa fa-copy" onclick="copyToClipboardCN('blog-rss-link', 'href')" style="cursor: pointer;" title="Copy RSS link to clipboard">

<a id="blog-rss-link" href="https://macvos.blogspot.com/feeds/posts/default" rel="alternate" target="_blank" title="RSS Feed" type="application/rss+xml"><i class="fa fa-rss"> RSS Feed <i class="fa fa-copy" onclick="copyToClipboardID('blog-rss-link', 'href')" style="cursor: pointer;" title="Copy RSS link to clipboard">

I have thought about combining the two functions into one, but i find that dangerous. In case you don't, here it is:
function copyToClipboard(element, attr) {
 var x = document.getElementById(element);
 if(x === undefined || x === null) {
  x = document.getElementsByClassName(element);
  if(x !== undefined && x !== null && x[0] !== undefined) {
   x = x[0];
  }
  else {
   x = undefined;
  }
 }
 if(x !== undefined) {
  var textarea = document.createElement("textarea");
  document.body.appendChild(textarea);
  textarea.value = x[attr];
  textarea.select();
  var status = document.execCommand('copy');
  textarea.remove();
 }
}

Restrict Lasso AJAX-file calls to the intended web page

 Permalink
Suppose you have a nice setup where a page interacts with the server via AJAX-calls and executes a Lasso file on the server to get some data. You don't want this file to be called directly via the URL-bar in a web browser, or via other self-made web pages by others who try to access it via a copy of your page. Anybody can see which AJAX-files your page is calling, so for some it is always a challenge to execute them outside the normal webpage to see what data will come up. Might be of interest! So you want to prevent that, somehow.

There is a Lasso-tag called referrer_url, which returns a string containing the URL that requested your AJAX-page. If you look into this string for a domain name or a path that only you have, you can block execution if the requestor is not coming from your server. When a page is called directly in the browser, the referrer_url is always an empty string. Which is logical, since the page was not referred to by another page.

Suppose I have a page mypage.html with a jQuery auto-complete implementation in it. This auto-complete can of course be used by more than one page and you do not want people to try it out in other ways.

...
...
<input type="text" id="inp1" size="25"><span id="desc1"></span>
...
...
<script>
$(document).ready(function() {
   $("#inp1").autocomplete({minLength:2, source: "ajax.lasso?p1=a&p2=b", select: function(e,u) { $("#inp1").val(u.item.value); $("#desc1").html((u.item.label).replace("(" + u.item.value + ")", "")); return false; } });
});
</script>


Simple protection:
[
if (referrer_url >> '/mypage.html' || referrer_url >> '/myotherpage.html');
...
...
/if;
]


Better protection:
[
if (string(referrer_url)->beginswith('http://my.domain.com/') &&
   (referrer_url >> '/mypage.html' || referrer_url >> '/myotherpage.html'));
...
...
/if;
]


So this gives you some protection from just try something-users. Add a login-system, which restricts the number of users that might want to hack your pages - you can trace their actions on your site. In that case, add a check if the user is logged in. You must execute your complete login-sequence in your AJAX-pages too, as with 'normal' pages, since the xhttprequest is a normal HTTP request and thus the browser sends the same HTTP-headers and cookies, etc.. to your AJAX-page.

More protection:
[
if (referrer_url >> '/mypage.html' || referrer_url >> '/myotherpage.html');
   var('loggedIn = false');

   include('checkuser.lasso');

   if($loggedIn);
      ...
      ...
   /if;
/if;
]


Even better protection:
[
if (string(referrer_url)->beginswith('http://my.domain.com/') &&
   (referrer_url >> '/mypage.html' || referrer_url >> '/myotherpage.html'));
   var('loggedIn = false');

   include('checkuser.lasso');

   if($loggedIn);
      ...
      ...
   /if;
/if;
]


But, as with everything web-related, nothing can be trusted.
 

Use Flot graphing library with Lasso Professional

 Permalink
I have created a quick example on how to create a graph with Flot and Lasso Professional. Flot is a really cool graphing library and Lasso is a cool programming language. Together, they create a great graph!

Alle getoonde foto's zijn (c) MHE Vos, Nederland.

All shown photo's are (c) MHE Vos, Netherlands.


© 1997- Marc Vos (and others)   -   Privacy Statement   -    Contact Me

On this website, Google Analytics is used to track visitor statistics. These are anonymised data about the number of visitors, which pages they visit on this site, from which regions they visit, which web browsers they use, etc.. You will also see non-personalised ads via Google AdSense. Cookies from Paddle or Paypal are placed when you click on a 'Buy now!' or 'Donate!' button, and possible cookies from Disqus when you use that system to comment on one or more blogposts.
Privacy Statement