• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
seegatesite header

Seegatesite.com

Seegatesite.com - Programming Tutorial , Sharing , How and Learn Together

  • TOOLS
    • Bootstrap Navbar Online Generator
    • Customize Sidebar Menu Bootstrap 3
    • Bootstrap Demo
  • ADVERTISE
  • CATEGORIES
    • Android
    • Blogging Tips
    • Database
    • CSS
    • Info Gadget
    • Javascript
    • Linux
    • PHP
    • Various
    • WordPress
  • Q&A
  • PHP
  • JAVASCRIPT
  • JQUERY
  • ANGULAR
  • WORDPRESS
  • SEO
  • REACT
🏠 » Javascript » How To Make Web Push Notifications in PHP, JQuery , AJAX And Mysql

How To Make Web Push Notifications in PHP, JQuery , AJAX And Mysql

By Sigit Prasetya Nugroho ∙ February 8, 2017 ∙ Javascript, PHP ∙ 92 Comments

Share : TwitterFacebookTelegramWhatsapp

Web Push Notifications not only useful for displaying the latest blog post to increase your website traffic, but you can apply them to information systems / web base CRUD applications. Since the smartphone era, browsers such as Chrome and Firefox has started massive changes against the product to make it more user-friendly and responsive. Firefox browser has equipped with push notification since version 44 and chrome on version 42.

How To Make Web Push Notifications In PHP, JQuery , AJAX And Mysql

The application of push notification script on a web page can be various, such as:

  • The notification to display the stock runs out.
  • Chat Notification If your system there is a chat feature.
  • A notification if there is a new mail.
  • Notification for stock movement.

And much more. I think the Web Push Notifications is a requirement but not required to be applied.

Related Articles :

  • How To Use Select2 Remote AJAX With Example in JQuery, PHP And MySQL
  • Web Applications as Desktop Flavor with Ajax Agent

Keep in mind the Web Push Notifications are not always useful. Often users are annoyed with a notification that is useless and annoying their performance.

Okay, as an example we will create a web push notification where a user does a broadcast message to another user with many options. The criteria as follows:

  1. Notification may appear several times according to schedule
  2. The user can define the interval the next notification will come out.
  3. The system will check the notification every 30 seconds
  4. A notification will be closed after 8 seconds.

See my video footage of how the application works

Table of Contents

  • 1 Lets start the tutorial How to make web push notifications in PHP, JQuery , AJAX And Mysql
    • 1.1 Okay, thus article about how to make web push notification in PHP, JQuery, Ajax and MySQL, hope usefull 🙂

Lets start the tutorial How to make web push notifications in PHP, JQuery , AJAX And Mysql

1. Create a new database with the name “notifikasi“.

Create Database Mysql Notifikasi For Web Push Notification Data

2. Create 2 table with name user and notif like the following image :

Create Tabel User Web Push Notification By Seegatesite.com.png

Create Tabel Notif Web Push Notification By Seegatesite.com

or please execute the following SQL code

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
30
31
32
33
DROP TABLE IF EXISTS 'notif';
 
CREATE TABLE 'notif' (
  'id' int(11) NOT NULL AUTO_INCREMENT,
  'notif_msg' text,
  'notif_time' datetime DEFAULT NULL,
  'notif_repeat' int(11) DEFAULT '1' COMMENT 'schedule in minute',
  'notif_loop' int(11) DEFAULT '1',
  'publish_date' timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  'username' varchar(13) DEFAULT NULL,
  PRIMARY KEY ('id')
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
 
/*Data for the table 'notif' */
 
insert  into 'notif'('id','notif_msg','notif_time','notif_repeat','notif_loop','publish_date','username') values (1,'hello, this is sample web push notification, you will redirect to seegatesite.com after click this notify','2017-02-08 08:48:54',1,0,'2017-02-08 08:47:54','ronaldo');
insert  into 'notif'('id','notif_msg','notif_time','notif_repeat','notif_loop','publish_date','username') values (2,'hello, this is sample web push notification, you will redirect to seegatesite.com after click this notify','2017-02-08 09:17:11',1,2,'2017-02-08 09:16:11','donald');
 
/*Table structure for table 'user' */
 
DROP TABLE IF EXISTS 'user';
 
CREATE TABLE 'user' (
  'username' varchar(20) DEFAULT NULL,
  'password' varchar(20) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
 
/*Data for the table 'user' */
 
insert  into 'user'('username','password') values ('admin','123');
insert  into 'user'('username','password') values ('donald','123');
insert  into 'user'('username','password') values ('ronaldo','123');
insert  into 'user'('username','password') values ('messi','123');

3.Create a new project folder as “notification”

4. Creates 8 PHP file PHP dan 1 js file like the following :

  • ajax.php : used to hold files to be executed by jquery ajax.
  • broadcast.php : used to create notification message.
  • dbconn.php : a class who used to create a MySQL connection with PDO
  • sql.php: a class who used to keep MySQL query syntax.
  • index.php : index or dashboard page.
  • isLogin.php : to checking if user is login or not.
  • login.php : login page
  • logout.php : logout code
  • mynotif.js : Javascript code who will execute the notification message

Create a login page

Copy the code below and save in login.php

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php SESSION_START(); if(isset($_SESSION['username'])) { header('Location: index.php'); } include "dbconn.php"; include "sql.php"; $sql = new sql(); $user = $sql->listUser();
?>
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
</head>
<body>
<h2>Login Application</h2>
 
 
<form method="post"  action="<?php echo $_SERVER['PHP_SELF']; ?>
">
<table>
<tr>
<td>Username</td>
 
 
<td><input type="text" name="username"></td>
 
</tr>
 
 
<tr>
<td>Password</td>
 
 
<td><input type="password" name="pass"></td>
 
</tr>
 
 
<tr>
<td colspan=2>
<hr>
</td>
 
</tr>
 
 
<tr>
<td><button type="submit" name="submit">Login</button></td>
 
</tr>
 
</table>
 
</form>
 
<?php if(isset($_POST['submit'])){ if(isset($_POST['username']) and isset($_POST['pass'])) { /*check login*/ $check = $sql->getLogin($_POST['username'],$_POST['pass']);
if($check[2] == 1)
{
$_SESSION['username'] = $_POST['username'];
header('Location: index.php');
}else
{
echo '* username or password not valid';
}
}
}
?>
<h2>How To Make Web Push Notifications in PHP, JQuery , AJAX And Mysql</h2>
 
 
<h3>http://seegatesite.com</h3>
 
 
<h4>admin user : admin , password : 123</h4>
 
 
<h5>user : ronaldo , password : 123</h5>
 
 
<h5>user : donald , password : 123</h5>
 
 
</body>
</html>

Create logout script.

Copy the code below and save at logout.php

1
<?php SESSION_START(); unset($_SESSION['username']); header('Location: login.php'); ?>

Create MySQL Connection With PDO

Copy the code below and save in dbconn.php file

1
2
3
4
5
6
<?php class dbconn { public $dblocal; public function __construct() { } public function initDBO() { $this->dblocal = new PDO("mysql:host=localhost;dbname=notifikasi;charset=latin1","root","123456",array(PDO::ATTR_PERSISTENT => true));
$this->dblocal->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
}
}
?>

Create class sql query syntax on the sql.php file

Copy the following code and save in sql.php

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php class sql extends dbconn { public function __construct() { $this->initDBO();
}
public function saveNotif($msg,$time,$loop,$loop_every,$user){
$db = $this->dblocal;
try
{
$stmt = $db->prepare("insert into notif(notif_msg, notif_time, notif_repeat, notif_loop,username) values(:msg , :bctime , :repeat , :loop,:user) ");
 
$stmt->bindParam("msg", $msg);
$stmt->bindParam("bctime", $time);
$stmt->bindParam("loop", $loop);
$stmt->bindParam("repeat", $loop_every);
$stmt->bindParam("user", $user);
$stmt->execute();
$stat[0] = true;
$stat[1] = 'sukses';
return $stat;
}
catch(PDOException $ex)
{
$stat[0] = false;
$stat[1] = $ex->getMessage();
return $stat;
}
}
public function updateNotif($id,$nextime)
{
$db = $this->dblocal;
try
{
$stmt = $db->prepare("update notif set notif_time = :nextime, publish_date=CURRENT_TIMESTAMP(), notif_loop = notif_loop-1 where id=:id ");
$stmt->bindParam("id", $id);
$stmt->bindParam("nextime", $nextime);
$stmt->execute();
$stat[0] = true;
$stat[1] = 'sukses';
return $stat;
}
catch(PDOException $ex)
{
$stat[0] = false;
$stat[1] = $ex->getMessage();
return $stat;
}
}
public function listNotifUser($user){
$db = $this->dblocal;
try
{
$stmt = $db->prepare("SELECT * FROM notif
WHERE username= :user
AND notif_loop > 0
AND notif_time <= CURRENT_TIMESTAMP()"); $stmt->bindParam("user", $user);
$stmt->execute();
$stat[0] = true;
$stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stat[2] = $stmt->rowCount();
return $stat;
}
catch(PDOException $ex)
{
$stat[0] = false;
$stat[1] = $ex->getMessage();
return $stat;
}
}
public function getLogin($user,$pass){
$db = $this->dblocal;
try
{
$stmt = $db->prepare("select * from user where username = :user and password = :pass");
$stmt->bindParam("user", $user);
$stmt->bindParam("pass", $pass);
$stmt->execute();
$stat[0] = true;
$stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stat[2] = $stmt->rowCount();
return $stat;
}
catch(PDOException $ex)
{
$stat[0] = false;
$stat[1] = $ex->getMessage();
return $stat;
}
}
public function listUser(){
$db = $this->dblocal;
try
{
$stmt = $db->prepare("select * from user");
$stmt->execute();
$stat[0] = true;
$stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stat[2] = $stmt->rowCount();
return $stat;
}
catch(PDOException $ex)
{
$stat[0] = false;
$stat[1] = $ex->getMessage();
return $stat;
}
}
public function listNotif(){
$db = $this->dblocal;
try
{
$stmt = $db->prepare("select * from notif");
$stmt->execute();
$stat[0] = true;
$stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stat[2] = $stmt->rowCount();
return $stat;
}
catch(PDOException $ex)
{
$stat[0] = false;
$stat[1] = $ex->getMessage();
return $stat;
}
}
}

Create PHP function to check user login

Copy the following code and save it in a file isLogin.php

1
<?php if(!isset($_SESSION['username'])) { header('Location: login.php'); } ?>

Creating a page for adding a list of notifications

Copy the following code and save the file broadcast.php

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php SESSION_START(); include "isLogin.php"; include "dbconn.php"; include "sql.php"; $sql = new sql(); $user = $sql->listUser();
?>
<!DOCTYPE html>
<html>
<head>
<title>Broadcast Menu</title>
</head>
<body>
<h2>Simple Broadcast Message Menu</h2>
 
<a href="index.php">Home</a> | <a href="logout.php">Logout</a>
<hr>
 
 
<form method="post"  action="<?php echo $_SERVER['PHP_SELF']; ?>
">
<table>
<tr>
<td>Message</td>
 
 
<td><textarea name="msg" cols="50" rows="4"></textarea></td>
 
</tr>
 
 
<tr>
<td>Broadcast time</td>
 
 
<td><select name="time"><option>Now</option></select> </td>
 
</tr>
 
 
<tr>
<td>Loop</td>
 
 
<td><select name="loops">
<?php
for ($i=1; $i<=5 ; $i++) { ?>
<option value="<?php echo $i ?>"><?php echo $i ?></option>
<?php } ?>
</select> time</td>
 
</tr>
 
 
<tr>
<td>Loop Every</td>
 
 
<td><select name="loop_every">
<?php
for ($i=1; $i<=60 ; $i++) { ?>
<option value="<?php echo $i ?>"><?php echo $i ?></option>
<?php } ?>
</select> Minute</td>
 
</tr>
 
 
<tr>
<td>For</td>
 
 
<td><select name="user">
<?php foreach ($user[1] as $key) { ?>
<option value="<?php echo $key['username'] ?>"><?php echo $key['username'] ?></option>
<?php } ?>
</select></td>
 
</tr>
 
 
<tr>
<td colspan=2>
<hr>
</td>
</tr>
 
 
<tr>
<td><button name="submit" type="submit">Broadcast </button></td>
 
</tr>
 
</table>
 
</form>
 
<?php if (isset($_POST['submit'])) { if(isset($_POST['msg']) and isset($_POST['time']) and isset($_POST['loops']) and isset($_POST['loop_every']) and isset($_POST['user'])) { $msg = $_POST['msg']; $time = date('Y-m-d H:i:s'); $loop= $_POST['loops']; $loop_every=$_POST['loop_every']; $user = $_POST['user']; /*save Notification*/ $save = $sql->saveNotif($msg,$time,$loop,$loop_every,$user);
if($save[0] == true)
{
echo '* save new notification success';
}else{
echo 'error save data : '.$save[1];
}
 
}else{
echo '* completed the parameter above';
}
}
?>
<table border=1>
<thead>
 
<tr>
<td>No</td>
 
 
<td>Next Schedule</td>
 
 
<td>Message</td>
 
 
<td>Remains</td>
 
 
<td>User</td>
 
</tr>
 
</thead>
 
 
<tbody>
<?php $a =1; $list = $sql->listNotif();
foreach ($list[1] as $key) {
?>
<tr>
<td><?php echo $a ?></td>
 
 
<td><?php echo $key['notif_time'] ?></td>
 
 
<td><?php echo $key['notif_msg'] ?></td>
 
 
<td><?php echo $key['notif_loop']; ?></td>
 
 
<td><?php echo $key['username'] ?></td>
 
</tr>
 
<?php $a++; } ?>
</tbody>
 
</table>
 
</body>
</html>

Explanation :

I will be a little bit of explaining some of the parameters used:

  • message : The content of the message.
  • broadcast time : time the message was sent.
  • loop : the number of messages to be sent
  • loop every : The time lag sending the first message to the next message
  • for : To whom this message is addressed

Create Index or Dashboard Page

Copy the following code and save it in a file index.php

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
30
<?php SESSION_START(); include "isLogin.php"; include "dbconn.php"; include "sql.php"; $sql = new sql(); $user = $sql->listUser();
?>
<!DOCTYPE html>
<html>
<head>
<title>test web browser notifikasi</title>
</head>
<body>
<h2>Dashboard </h2>
 
<?php if($_SESSION['username'] == 'admin') { ?>
<a href="broadcast.php">Notification Menu</a> |
<?php } ?>
<a href="logout.php">Logout</a>
<hr>
 
 
<h4>Welcome back <strong><?php echo $_SESSION['username'] ?></strong></h4>
 
 
 
This is example web push notification from <a href="https://seegatesite.com">seegatesite.com</a>, wait your notify please :)
<!-- Jquery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<!-- Notifikasi Script -->
<script src="mynotif.js"></script>
</body>
</html>

Explanation :

Notification script will be executed every 30 seconds.

Create a file that will be called by the Jquery ajax

Copy the following code and save it in a file ajax.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php SESSION_START();
include "isLogin.php";
include "dbconn.php";
include "sql.php";
$sql = new sql();
$array=array();
$rows=array();
$listnotif = $sql->listNotifUser($_SESSION['username']);
foreach ($listnotif[1] as $key) {
$data['title'] = 'Notification Title';
$data['msg'] = $key['notif_msg'];
$data['icon'] = 'http://localhost/notification/avatar2.png';
$data['url'] = 'https://seegatesite.com';
$rows[] = $data;
// update notification database
$nextime = date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+($key['notif_repeat']*60));
$sql->updateNotif($key['id'],$nextime);
}
$array['notif'] = $rows;
$array['count'] = $listnotif[2];
$array['result'] = $listnotif[0];
echo json_encode($array);
?>

Explanation: After 30 seconds, the javascript function will take the list of notification message who never been share and will accommodate the data into an array variable

Create a javascript file that will execute the notification

Copy the following code and save it in a file mynotif.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
$(document).ready(function() {
checknotif();
setInterval(function(){ checknotif(); }, 10000);
});
function checknotif() {
if (!Notification) {
$('body').append('
<h4 style="color:red">*Browser does not support Web Notification</h4>
 
');
return;
}
if (Notification.permission !== "granted")
Notification.requestPermission();
else {
$.ajax(
{
url : "ajax.php",
type: "POST",
success: function(data, textStatus, jqXHR)
{
var data = jQuery.parseJSON(data);
if(data.result == true){
var data_notif = data.notif;
for (var i = data_notif.length - 1; i >= 0; i--) {
var theurl = data_notif[i]['url'];
var notifikasi = new Notification(data_notif[i]['title'], {
icon: data_notif[i]['icon'],
body: data_notif[i]['msg'],
});
notifikasi.onclick = function () {
window.open(theurl);
notifikasi.close();    
};
setTimeout(function(){
notifikasi.close();
}, 5000);
};
}else{
 
}
},
error: function(jqXHR, textStatus, errorThrown)
{
 
}
});
 
}
};

Explanation: The main part of this article, contained in the above code.

1
2
3
4
$(document).ready(function() {
checknotif();
setInterval(function(){ checknotif(); }, 30000);
})

When the page is ready, will execute the javascript checknotif() function  and it is always executed after 30 seconds.

1
2
3
4
5
6
7
if (!Notification) {
$('body').append('
<h4 style="color:red">*Browser does not support Web Notification</h4>
 
');
return;
}

Javascript will check whether the browser supports notification feature

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
30
31
32
33
34
35
36
37
38
if (Notification.permission !== "granted")
Notification.requestPermission();
else {
$.ajax(
{
url : "ajax.php",
type: "POST",
success: function(data, textStatus, jqXHR)
{
var data = jQuery.parseJSON(data);
if(data.result == true){
var data_notif = data.notif;
for (var i = data_notif.length - 1; i &gt;= 0; i--) {
var theurl = data_notif[i]['url'];
var notifikasi = new Notification(data_notif[i]['title'], {
icon: data_notif[i]['icon'],
body: data_notif[i]['msg'],
});
notifikasi.onclick = function () {
window.open(theurl);
notifikasi.close();    
};
setTimeout(function(){
notifikasi.close();
}, 8000);
};
}else{
 
}
},
error: function(jqXHR, textStatus, errorThrown)
{
 
}
});
 
}

The browser will submit a request to web push notification. Users will get a request like the following picture:

Web Push Notification Alert Seegatesite.com

If the access receipt, then javascript will execute ajax to check for notification of each user.

1
2
3
4
5
6
7
8
9
10
11
12
var theurl = data_notif[i]['url'];
var notifikasi = new Notification(data_notif[i]['title'], {
                                  icon: data_notif[i]['icon'],
                                  body: data_notif[i]['msg'],
});
notifikasi.onclick = function () {
window.open(theurl);
notifikasi.close();    
};
setTimeout(function(){
notifikasi.close();
}, 8000);

To show notification with the code above.

Lets check from the browser http://localhost/notification.

Finish, Any question ? Download link below to get full source

Url : http://wp.me/a65Dpx-I9

Okay, thus article about how to make web push notification in PHP, JQuery, Ajax and MySQL, hope usefull 🙂

update : zip file error, re-upload!!

Another Javascript Related Post :

  • Adept Using Datatables Plugin In 10 Minutes For Beginners (Tutorial)
  • The Using Of Reactstrap And React-Table, Suitable For Beginners
  • Tutorial Create Simple Block UI Using React JS
  • How To Implement Login Page And Protected Route ReactJS
  • Complete Tutorial React Router Dom For Beginners (Easy-To-Understand)
  • The Right Way Understanding React Lifecycle For Beginners

Avatar for Sigit Prasetya Nugroho

About Sigit Prasetya Nugroho

This site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.

Reader Interactions

Comments

  1. Avatar for biplobbiplob says

    March 21, 2017 at 5:16 am

    ( ! ) Fatal error: Uncaught exception ‘PDOException’ with message ‘SQLSTATE[28000] [1045] Access denied for user ‘root’@’localhost’ (using password: YES)’ in C:\wamp1\www\notification\dbconn.php on line 11
    ( ! ) PDOException: SQLSTATE[28000] [1045] Access denied for user ‘root’@’localhost’ (using password: YES) in C:\wamp1\www\notification\dbconn.php on line 11
    Call Stack
    # Time Memory Function Location
    1 0.0018 679744 {main}( ) ..\login.php:0
    2 0.0054 746104 sql->__construct( ) ..\login.php:9
    3 0.0054 746104 dbconn->initDBO( ) ..\sql.php:5
    4 0.0055 747352 PDO->__construct( ) ..\dbconn.php:11
    give a solution

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      March 23, 2017 at 7:25 am

      Change with your database username and password in dbconn.php

      Reply
  2. Avatar for mrxmrx says

    March 29, 2017 at 7:42 am

    kodingan login salah!mohon cek ulang..

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      March 29, 2017 at 7:52 am

      salah? saya coba baik2 saja gan. errornya apa ya?

      terimakasih

      Reply
  3. Avatar for mrxmrx says

    March 30, 2017 at 2:07 am

    include(isLogin.php): failed to open stream: No such file or directory in C:\xampp\htdocs\notif_wa\index.php on line 1
    include(): Failed opening ‘isLogin.php’ for inclusion (include_path=’C:\xampp\php\PEAR’) in C:\xampp\htdocs\notif_wa\index.php on line 1

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      March 30, 2017 at 3:03 am

      Kalo error ini mungkin path anda ada yang salah.. 🙂

      Reply
  4. Avatar for mrxmrx says

    March 30, 2017 at 2:12 am

    Notice: Undefined offset: 2 in C:\xampp\htdocs\notif_wa\login.php on line 58

    ketika mau login, tidak dapat masuk yg dimaksud $check[2] ==1 nah si angka 2 nya undefined thx before

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      March 30, 2017 at 3:01 am

      ooo itu karena ketika memanggil getlogin terdapat error dan dibagian catch errornya tidak saya sertakan $stat[2] karena asumsi saya program tidak ada error karena ini hanya contoh singkat untuk notifikasi. Okay, silahkan coba solusi berikut
      1. silahkan anda buka dbconn.php dan isikan nama database, username dan password mysql anda dengan benar.
      2. Kemudian Buka sql.php, cari function getLogin() dan di bagian catch tambahkan kode $stat[2]=0 seperti kode berikut:
      [php]
      public function getLogin($user,$pass){
      $db = $this->dblocal;
      try
      {
      $stmt = $db->prepare("select * from user where username = :user and password = :pass");
      $stmt->bindParam("user", $user);
      $stmt->bindParam("pass", $pass);
      $stmt->execute();
      $stat[0] = true;
      $stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC);
      $stat[2] = $stmt->rowCount();
      return $stat;
      }
      catch(PDOException $ex)
      {
      $stat[0] = false;
      $stat[1] = $ex->getMessage();
      $stat[2] = 0;
      return $stat;
      }
      }
      [/php]
      3. Dan di bagian login.php di bagian script php nya diubah seperti ini:
      [php]
      //……………..
      if(isset($_POST[‘submit’])){
      if(isset($_POST[‘username’]) and isset($_POST[‘pass’]))
      {
      $check = $sql->getLogin($_POST[‘username’],$_POST[‘pass’]);
      if($check[2] == 1)
      {
      $_SESSION[‘username’] = $_POST[‘username’];
      header(‘Location: index.php’);
      }else
      {

      echo ‘* error : ‘.$check[1];
      }
      }
      }
      [/php]

      Semoga membantu, jika masih ada error silahkan hubungi saya kembali. terimakasih

      Reply
  5. Avatar for mrxmrx says

    March 30, 2017 at 4:47 am

    bolehkah saya minta extract dari program notifikasi tersebut??(berbentuk .zip)karna saya sudah geleng geleng kepala hehe.. makasih atas fastrespon ya sukses slalu web nya

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      March 30, 2017 at 9:33 am

      sudah saya sediakan kok mas di bagian akhir artikel… https://seegatesite.com/notification-2/

      Reply
  6. Avatar for joko Majoko Ma'ruf says

    April 25, 2017 at 2:26 am

    makasih mas, terbantu sekali 😉

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      April 25, 2017 at 7:09 am

      sama-sama 🙂

      Reply
  7. Avatar for joko Majoko Ma'ruf says

    April 25, 2017 at 10:18 am

    mas, cara set waktu show upnya notifikasinya gmana ya?? saya coba g pakai setinterval kok masih hilang sendiri

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      April 25, 2017 at 10:28 am

      [php]
      setTimeout(function(){
      notifikasi.close();
      },20000);
      [/php]
      dibagian javascript gan function checknotif, ubah 8000 menjadi 20000 (20 detik)

      Reply
  8. Avatar for prasannaprasanna says

    May 25, 2017 at 12:24 pm

    my code is working but not notification

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      May 25, 2017 at 12:59 pm

      check again your browser notification setting, this code work perfectly 🙂

      Reply
  9. Avatar for maria noemimaria noemi says

    July 31, 2017 at 7:32 pm

    Hi, good morning, first of all thanks for the tutorial, it’s great.
    I have a question for you, is it possible that the notifications do not close or disappear until we click on them ?, I comment because my notifications are closed, but I would like that they will only be closed if I click on them.
    thank you very much

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      August 1, 2017 at 1:22 am

      you can remove the following script in the function checknotif

      1
      2
      3
      setTimeout(function(){
      notifikasi.close();
      }, 5000);

      Reply
  10. Avatar for AndreaAndrea says

    August 24, 2017 at 6:05 pm

    Hi, thanks is a great tutorial.
    Maybe i lost something but i’m tryng in localhost…
    It works properly on my desktop browsers (firefox and chrome)
    but no notification on my smarpthone (chrome browser).

    On my smartphone i’m connected to the index page and logged in.

    What i’m wrong?

    Thanks

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      August 25, 2017 at 2:35 am

      Sorry I have not found the solution yet. I’ll update if it works 🙂

      Reply
  11. Avatar for MarceloMarcelo says

    November 13, 2017 at 4:42 pm

    Hello, thanks for the great tutorial
    I have a doubt. For the user to receive the notification does he need to have the system open?

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      November 14, 2017 at 1:25 am

      Dear marcelo,

      I dont understand what are you mean about system open?

      🙂

      Reply
      • Avatar for MarceloMarcelo says

        November 15, 2017 at 2:14 am

        If it is necessary for the user to enter the system to receive the notification. For example, when I turn on my notebook, before I even open the browser I already receive notifications from some pages.

        Reply
        • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

          November 15, 2017 at 2:22 am

          Yes the user needs to open the browser to get notifications, because push notifications is the default feature from the browser

          CMIIW 🙂

          Reply
  12. Avatar for Maxmiler FreitasMaxmiler Freitas says

    November 13, 2017 at 10:00 pm

    The notification only comes if I access the home page. How to send the notification automatically?

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      November 14, 2017 at 1:24 am

      using setInterval javascript

      https://www.w3schools.com/jsref/met_win_setinterval.asp

      Reply
      • Avatar for Maxmiler FreitasMaxmiler Freitas says

        November 14, 2017 at 11:29 am

        Thank you! I’ll work on it.

        Reply
  13. Avatar for MarceloMarcelo says

    November 15, 2017 at 2:08 am

    Can I customize the style of the notification?

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      November 15, 2017 at 2:20 am

      Sorry, I’ve never tried it to change the push notifications style 🙂

      Reply
  14. Avatar for Maxmiler FreitasMaxmiler Freitas says

    November 15, 2017 at 1:12 pm

    I access the page from another browser, I accept the notifications, when I fire them they do not go to that browser. Only goes to who is registered in the bank. Can you send it to someone who is not registered?

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      November 16, 2017 at 1:31 am

      In the notification example I created, I sent a notification to the selected user. If you want to send a notification to the unregister user, you must change the mysql query to retrieve the data without involving the user to share to all unregister users.

      Reply
  15. Avatar for Ehsan KhanEhsan Khan says

    January 8, 2018 at 2:55 pm

    Working Great .. thanks…. can this work with cookies without login system?

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      January 9, 2018 at 9:12 am

      It should be, but I’ve never tried it 🙂

      Reply
    • Avatar for bajabaja says

      January 22, 2018 at 5:32 am

      sir how to change the mysql query to receive notification the all user?

      Reply
  16. Avatar for yokimyokim says

    January 22, 2018 at 5:27 am

    help me sir

    Reply
  17. Avatar for bajabaja says

    January 22, 2018 at 5:42 am

    Sigit Prasetya Nugroho sir your video is great its very helpful on my thesis. im trying to change mysql query to notify the unregistered user but i have no idea both in php and mysql query im a newbie.

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      January 23, 2018 at 1:38 am

      Sory, i dont understand what you want, but if you need query to all unregister user you can use the following query

      1
      2
      3
      4
      $stmt = $db->prepare("SELECT * FROM notif
      WHERE (username not in(select username from user))
      AND notif_loop > 0
      AND notif_time <= CURRENT_TIMESTAMP()");

      Hope useful 🙂

      Reply
      • Avatar for BajaBaja says

        January 23, 2018 at 2:06 am

        thanks sir,, I have another question sir. if I want to send a notification to all user what should I do? can u give me idea?

        Reply
  18. Avatar for BajaBaja says

    January 23, 2018 at 3:37 am

    hello sir. its possible if the admin send the notification to all the user without selecting the username.? because I want to send notification to all the user, please help me if you have an idea and how to change the code? thanks!!

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      January 23, 2018 at 4:45 am

      logically as follows,

      change the code in broadcast.php

      add new option value in select box user –> value=”alluser”

      and then , add change the query listNotifUser with code below

      1
      2
      3
      4
      $stmt = $db->prepare("SELECT * FROM notif
      WHERE (username= :user or username= 'alluser')
      AND notif_loop > 0
      AND notif_time <= CURRENT_TIMESTAMP()");

      Reply
      • Avatar for bajabaja says

        January 23, 2018 at 5:32 am

        For

        <option value="”>

        sir can you edit for me how to change? the value hehehehe sorry I’m still learning in php hehehe

        Reply
        • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

          January 23, 2018 at 6:08 am

          here

          1
          <option value="alluser">all user</option>

          Reply
          • Avatar for BajaBaja says

            January 23, 2018 at 8:17 am

            thank you sir

  19. Avatar for farheenfarheen says

    January 23, 2018 at 5:08 am

    working perfectly on localhost but not on my server ?

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      January 23, 2018 at 5:09 am

      can you show me the error ?

      Reply
      • Avatar for farheenfarheen says

        January 23, 2018 at 5:18 am

        there is no no error
        able to send but not receiving

        Reply
        • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

          January 23, 2018 at 5:20 am

          Check your notifications Allow or block in your browser.

          this script not working on phone device

          🙂

          Reply
          • Avatar for farheenfarheen says

            January 23, 2018 at 6:28 am

            it still didn’t work

    • Avatar for pkpk says

      February 27, 2019 at 10:14 am

      I am also having same problem its not working in web server , also not getting any errors.

      Reply
  20. Avatar for BajaBaja says

    January 27, 2018 at 8:50 am

    1
    2
    3
    4
    5
    Push.create("NEGROS ISLAND FESTIVAL",{
    body: "masskara festival sa bacolod",
    icon: "image/CPSU_official_logo_seal.jpg",
    });

    sir can you help me again this script on how to notify automatically every week and every month?
    I know you are the one that can solved my thesis thank you

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      January 29, 2018 at 1:13 am

      every week :

      You can do mysql search using the day parameter, an example every monday

      1
      2
      3
      4
      $stmt = $db->prepare("SELECT * FROM notif
      WHERE (username= :user or username= 'alluser')
      AND notif_loop > 0
      AND notif_time <= CURRENT_TIMESTAMP() and dayname(now()) = 'monday'");

      Every month :

      You can do mysql search using the date parameter, an example every 5th in a month

      1
      2
      3
      4
      $stmt = $db->prepare("SELECT * FROM notif
      WHERE (username= :user or username= 'alluser')
      AND notif_loop > 0
      AND notif_time <= CURRENT_TIMESTAMP() and day(now()) = '5'");

      Hope useful 🙂

      Reply
  21. Avatar for YohanYohan says

    February 8, 2018 at 1:58 pm

    Hi,

    Working great, but I want to use it on smartphone (iOS and Androide) but it’s doesn’t work.
    That’s possible to use it on smartphone ?

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      February 9, 2018 at 8:03 am

      yes, its not work in smartphone now. You can use google firebase to create push notification in pc browser or smartphone browser. But i have never tried it. Check it out here https://firebase.google.com/docs/cloud-messaging/?hl=en

      Reply
  22. Avatar for Usama SaeedUsama Saeed says

    February 16, 2018 at 4:12 pm

    Hello sir,

    Working great with one notification, but I want to send multiple notifications but it’s doesn’t work.
    Please guide me what should I do?

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      February 17, 2018 at 3:38 am

      can u share your multiple code to me ??

      🙂

      Reply
      • Avatar for usama saeedusama saeed says

        February 17, 2018 at 3:02 pm

        same as tutorial code, just change for loop to foreach loop. Both didnt work for me
        if(data.result == true){
        var data_notif = data.notif;
        data_notif.forEach(function(entry) {
        console.log(entry);
        var theurl = entry[‘url’];
        var notifikasi = new Notification(entry[‘title’], {
        icon: entry[‘icon’],
        body: entry[‘message’],
        });
        notifikasi.onclick = function () {
        window.open(theurl);
        notifikasi.close();
        };
        setTimeout(function(){
        notifikasi.close();
        }, 5000);
        });

        Reply
        • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

          February 19, 2018 at 1:15 am

          You can check your error from console.log . what is the error show?

          Reply
          • Avatar for usamausama says

            February 20, 2018 at 3:50 pm

            No error on console. Same tutorial code not working for multiple notification for me

          • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

            February 21, 2018 at 8:22 am

            working perfectly with foreach in my test 🙂

  23. Avatar for Mustafa ContractorMustafa Contractor says

    February 18, 2018 at 5:21 pm

    what if i want to send notification to all the users in the database?

    Also, how is it possible that not just the login user but any visitor who Allows notification will receive notifications even if he is not registered?

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      February 19, 2018 at 1:22 am

      You can read the comment before

      https://seegatesite.com/how-to-make-web-push-notifications-in-php-jquery-ajax-and-mysql/#comment-4940

      Reply
  24. Avatar for AlfredoAlfredo says

    March 21, 2018 at 5:09 pm

    Very good tutorial !

    Reply
  25. Avatar for maruti dangemaruti dange says

    April 4, 2018 at 12:20 pm

    Fatal error: Uncaught exception ‘PDOException’ with message ‘SQLSTATE[HY000] [1045] Access denied for user ‘root’@’localhost’ (using password: YES)’ in C:\xampp\htdocs\notification\dbconn.php:7 Stack trace: #0 C:\xampp\htdocs\notification\dbconn.php(7): PDO->__construct(‘mysql:host=loca…’, ‘root’, ‘123456’, Array) #1 C:\xampp\htdocs\notification\sql.php(1): dbconn->initDBO() #2 C:\xampp\htdocs\notification\login.php(9): sql->__construct() #3 {main} thrown in C:\xampp\htdocs\notification\dbconn.php on line 7

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      April 4, 2018 at 3:37 pm

      1
      Access denied for user ‘root’@’localhost’

      Change your database settings with yours 🙂

      Reply
  26. Avatar for maruti dangemaruti dange says

    April 5, 2018 at 2:30 am

    thanks sir
    i have tried but still its not getting can u help me more…………
    Access denied for user ‘root’@’localhost’
    Change your database settings with yours How to change in proper way, i am might going wrong

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      April 5, 2018 at 3:38 am

      Have you checked mysql database settings? Open the dbconn.php file and customize it with your own database settings 🙂

      Reply
      • Avatar for maruti dangemaruti dange says

        April 5, 2018 at 7:50 am

        thank u so much sir,
        now everything is working But Notification is NOT Showing when the user is login

        Reply
        • Avatar for maruti dangemaruti dange says

          April 5, 2018 at 8:41 am

          i checked in console this is only 1 error :
          Uncaught Syntax Error: Invalid or unexpected token mynotif.js:10

          Reply
          • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

            April 5, 2018 at 9:24 am

            Click your error from console. and check it. your error in row 10 mynotif.js

            1
            $('body').append('<h4 style="color:red">*Browser does not support Web Notification</h4>');

          • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

            April 5, 2018 at 9:24 am

            delete the space 🙂

  27. Avatar for maruti dangemaruti dange says

    April 11, 2018 at 12:59 pm

    hi sir
    great tutorial thanks a lot .
    sir i wants to store the notification in user side whenever user wants to see what are those notification . please help me sir how to do it

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      April 13, 2018 at 1:36 am

      please more specific 🙂

      Reply
  28. Avatar for maruti dangemaruti dange says

    April 12, 2018 at 9:30 am

    please help me sir i am waiting for your reply

    Reply
  29. Avatar for ThiagoThiago says

    August 15, 2018 at 6:30 am

    Excelent code. Please, send the code to working mobile devices…..

    This code not work in android e Ios devices

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      August 17, 2018 at 1:16 am

      not working in mobile phone

      Reply
  30. Avatar for gurvinder kaurgurvinder kaur says

    August 16, 2018 at 11:01 am

    No error… but still notification not working

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      August 17, 2018 at 1:16 am

      not working in mobile phone

      Reply
  31. Avatar for GurvinderGurvinder says

    August 16, 2018 at 11:14 am

    Works amazingly now… thank you sir… 🙂

    Reply
  32. Avatar for RABRAB says

    September 21, 2018 at 6:06 am

    Hi Sir! works perfectly.. Thank you very much!

    Reply
  33. Avatar for fengfeng says

    October 3, 2018 at 3:57 am

    hello. sir.
    I didn’t get any bug. But I can’t get the notification.
    Please help.Thanks

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      October 5, 2018 at 1:10 am

      using phone or pc ?

      Reply
  34. Avatar for RanaRana says

    December 16, 2018 at 6:21 pm

    hello sir..
    without login Notification alert?

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      December 17, 2018 at 1:24 am

      Yes. You can do this without creating a login page. The login page is only used to search for messages to be sent

      Reply
  35. Avatar for Mark LewisMark Lewis says

    January 3, 2019 at 8:00 pm

    Is it possible to detail how to do this without a login necessary? Ive tried playing with the code but cant seem to get it to work without the login.

    Reply
  36. Avatar for Khatri PavanKhatri Pavan says

    September 17, 2019 at 7:13 am

    Can you provide me a code of chat message notification for codeigniter in localhost database not in online database.

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      September 23, 2019 at 8:50 am

      sorry I have never tried it

      Reply
  37. Avatar for zokhamzokham says

    January 16, 2020 at 4:29 am

    Hello there,

    Is it complusory to have SSL certificate to implement push notifications on localhost or live server please reply asap.

    Thanks.

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      January 18, 2020 at 7:09 am

      Not mandatory

      Reply
  38. Avatar for RafaelRafael says

    May 14, 2020 at 2:49 am

    Hola, hice el instructivo pero al ingesar a la pagina simplemente no me aparece la notificacion. Uso Ubuntu 18.
    Hay algun requerimiento de instalacion?

    Gracias.

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      May 14, 2020 at 3:13 am

      check your PHP version. Ubuntu 18 has used PHP version 7 or can you show me your error message in your browser console ?

      Reply
  39. Avatar for maqinmaqin says

    January 22, 2021 at 10:02 am

    Sukses Mas, Terima kasih.

    oh iya ini belum ada pengembangan untuk di smartphone yah? saya perhatikan sudah banyak yg tanya juga di komentar.

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      January 24, 2021 at 10:53 am

      maaf belom ada pengembangan untuk mobile..kalo smartphone khususnya android… sekarang hanya mendukung firebase push notification.CMIIW 🙂

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Welcome to my Home,

Avatar for Sigit Prasetya NugrohoThis site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.



Popular Articles

Checked checkbox AdminLTE Bootstrap in Jquery

November 4, 2014 By Sigit Prasetya Nugroho 7 Comments

Simple create date format validation with jqueryUI

December 21, 2014 By Sigit Prasetya Nugroho Leave a Comment

Create Simple Progress Bar for Fake Online Generator with Jquery

January 10, 2015 By Sigit Prasetya Nugroho Leave a Comment

22+ Coolest Free Jquery Plugin For Premium Theme

October 3, 2015 By Sigit Prasetya Nugroho Leave a Comment

Easy Build Your Anti Copy Paste Plugin

October 6, 2015 By Sigit Prasetya Nugroho Leave a Comment

Popular Tags

adminlte (15) adsense (13) adsense tips (4) affiliate amazon (13) amazon (12) Android (8) angular (16) angular 4 (12) angular 5 (4) asin grabber (3) Bootstrap (27) codeigniter (5) create wordpress theme (5) crud (8) css (6) free wordpress theme (7) google adsense (4) imacros (4) increase traffic (6) jquery (34) laravel (10) laravel 5 (5) learn android (5) modal dialog (5) mysql (6) nodeJs (4) optimize seo (4) pdo (6) php (30) plugin (53) pos (7) Publisher Tips (5) react (3) Reactjs (7) SEO (37) theme (17) tutorial angular (5) tutorial angular 4 (6) tutorial javascript (10) tutorial javascript beginners (4) twitter (3) widget (3) wordpress (18) wordpress plugin (13) XMLRPC (5)




  • About
  • Contact Us
  • Disclaimer
  • Privacy Policy
  • Terms and Conditions

©2021 Seegatesite.com