I've got a text I don't want to be copied by users.
To avoid that, I'm using this code:
index.php
<?php
session_start();
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
for ($i = 0; $i < 100; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
$_SESSION['token'] = $randomString;
?>
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>Test</title>
<script src="../jquery.js"></script>
</head>
<body>
<script>
$(document).ready(function(){
$("#content").load("page.php?token=<?php echo $_SESSION['token']; ?>", function (responseText, textStatus, req) {if (textStatus == "error") {
$("#content").html('An error occurred :(');
}
});
});
</script>
<div id="content">Please wait...</div>
</body>
page.php
<?php
session_start();
if(!empty($_SESSION['token']) AND $_GET['token']==$_SESSION['token']){echo '
<script>
function error(){
alert("This text is protected");
}
$(document).ready(function(){
$(document).mousedown(function(e){
if( e.button == 2 ) {
error();
return false;
}
});
$(document).keydown(function(){
error();
return false;
});
});
</script>
Text...';
unset($_SESSION['token']);
}
else{echo 'Error.';
}
?>
Is this method reliable?