Using the database to get the class name is not optimal until it can be done locally. You should define a array of all class names, and then pick one up them by array_rand
, some thing like this:
// php code
<?php
$classes = array('class1','class2','class3','class4');
$class_name = $classes[array_rand($classes)];
?>
// html code
<div class="<? php echo $class_name; ?>">anything</div>
// css code
<style>
.<? php echo $class_name; ?> {
// your css codes
}
</style>
Note: you must know that you can't use php codes at .css
file, then you should write all css codes that you want to be dynamic in your .php
file and use <style> stuff </style>
.
Meanwhilem, as @sємsєм said, you can creat dynamic html tags.
Some thing like this: (full code)
// php code
<?php
// dynamic class
$classes = array('class1','class2','class3','class4');
$class_name = $classes[array_rand($classes)];
// dynamic tags
$tags_statr = array('','<div>','<div><div>','<div><p>','<span><div>');
$tags_end = array('','</div>','</div></div>','</div></p>','</span></div>');
$numb = array_rand($tags_statr);
?>
// html code
<?php echo $tags_statr[$numb]; ?>
<div class="<? php echo $class_name; ?>">anything</div>
<?php echo $tags_end[$numb]; ?>
// css code
<style>
.<? php echo $class_name; ?> {
// your css codes
}
</style>
And for higher security, You can put your content (Here 'anything') (in addition to the external dynamic tags). for example:
<span1>anything</span1> // <span1> changed to <span2,3,4....>
In this case, the adjacent tag with data is also dynamic, And this makes it harder for crawlers.
Finally, I must say that you can't prevent crawlers utterly, you just make it difficult. If you really want to protect your data, you can do things like them:
- Increased restrictions for users. (e.g Only registered users can see important information)
- Monitor IP that uses of your website (and if suspicious, block it)
- Use relevant software. (e.g To limit the search for an IP on a daily basis)