Showing posts with label scripts_tutorials. Show all posts
Showing posts with label scripts_tutorials. Show all posts

Thursday, 3 November 2016

Published 04:48:00 by with 0 comment

How to display Date and Time in Javascript

Hi,
In this script, I will show you how to display the date and time in real time in a web page using Javascript.


The script is simple, we will use the Javascript Object Date to get the date and the time. We will display the month in words(January, February...).

This is the code:
date_time.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function date_time(id)
{

        date = new Date;
        year = date.getFullYear();
        month = date.getMonth();
        months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'Jully', 'August', 'September', 'October', 'November', 'December');
        d = date.getDate();
        day = date.getDay();
        days = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
        h = date.getHours();
        if(h<10)
        {
                h = "0"+h;
        }
        m = date.getMinutes();
        if(m<10)
        {
                m = "0"+m;
        }
        s = date.getSeconds();
        if(s<10)
        {
                s = "0"+s;
        }
        result = ''+days[day]+' '+months[month]+' '+d+' '+year+' '+h+':'+m+':'+s;
        document.getElementById(id).innerHTML = result;
        setTimeout('date_time("'+id+'");','1000');
        return true;
}
date_time.html
1
2
3
4
5
6
7
8
9
10
11
12
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Display Date and Time in Javascript</title>
        <script type="text/javascript" src="date_time.js"></script>
    </head>
    <body>
            <span id="date_time"></span>
            <script type="text/javascript">window.onload = date_time('date_time');</script>
    </body>
</html>


I hope this script will be useful.
Read More
      edit
Published 04:23:00 by with 0 comment

script to make a redirection with a timeout in milliseconds

Hi,
This is a litle script to make a redirection with a timeout in milliseconds.
You just have to change 5000(5 seconds) by the number of milliseconds before the redirection and http://www.fluxntech.com/ by the destination page:
1
window.setTimeout("location=('http://www.fluxntech.com');",5000);

I hope this script will be useful.
Read More
      edit
Published 04:15:00 by with 0 comment

How to redirect php page header location RewriteRule

Hi,
In this php trick, I will show you two ways to make redirections. The first will be in PHP using the header function and the second one will use the URL Rewriting using the .htaccess file.

Method #1

This way is dynamic because you can execute a php code before. Be sure that there is no (X)html code or any echo before the redirection:
1
2
3
<?php
header('Location: http://www.fluxntech.com');
?>
You only have to change http://www.fluxntech.com by the URL of the destination page.

Method #2

This way use URL Rewriting, so you have to create a .htaccess file and he must contain the following code in the beginning:
1
RewriteEngine on
That will activate the URL Rewriting. In the following code, when someone go to mypage.html, he will be automatically be redirected to mypage2.html:
1
RewriteRule ^mypage\.html$  /mypage2.html [R]
You have to add the code above in you .htaccess file. mypage.html don't need to realy exist in the server to make the redirection.

I hope this trick will be useful.
Read More
      edit
Published 04:00:00 by with 0 comment

how to get the execution time of a script and to display it

Hi,
In this script, I will show you how to get the execution time of a script an to display it.
This script is very simple, we will get the micro-seconds in the beginning and in the and of the script using the microtime function of PHP. Then, we will do a subtraction to get the elapsed time during the script execution.
This is the code to use:
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
function timer()
{

    $time = explode(' ', microtime());
    return $time[0]+$time[1];
}
$beginning = timer();
?>

<html>
    <!-- The content of your page -->
        Page generated in <?php echo round(timer()-$beginning,6); ?> seconds.
    </body>
</html>
I hope this script will be useful.
Read More
      edit
Published 03:50:00 by with 0 comment

How to create custom 404 error pages

Hi,
In this tutorial, I will show you how to create custom 404 error pages.
First, you have to create a .htaccess file in the root of your web site.

This is the content of your .htaccess file:
.htaccess
1
ErrorDocument 404 /erreur_404.html

Then, you have to create the page erreur_404.html, she will be the custom 404 error page:
1
2
<h1>404 Error</h1>
<h3>The page you are looking for does not exist.</h3>

If you want to customize other errors you only have to add another line in the .htaccess file and to create the custom page of your error.

I hope this trick will be useful.
Read More
      edit