
mythri
Members-
Posts
85 -
Joined
-
Last visited
Recent Profile Visitors
2,503 profile views
mythri's Achievements
-
in my login.php i set session like this ini_set('session.gc_maxlifetime', 315360000); session_set_cookie_params(315360000); session_start(); and in session.php, which includes in all the pages include('Connection.php'); if((isset($_SESSION['uid']))) { if (!empty($_SERVER['HTTPS'])) { define('RootPath', 'https://mywebsite'); } else { define('RootPath', 'http://mywebsite'); } $stmt = $con->prepare("SELECT * FROM users"); $stmt->execute(); $user = $stmt->fetch(); $_SESSION['name'] = $user['fname'].' '.$user['lname']; $_SESSION['fname'] = $user['fname']; $_SESSION['type'] = $user['type']; $_SESSION['Path'] = RootPath; } else if(!isset($_SESSION['uid'])) { header("location:index.php"); exit(); } ?> do i need to include this file in service-worker.js?
-
I have a php script and i made it as pwa with web-push notifications. Whenever i re-open the app, it asks me to login, i want to keep it logged in. these are the files for pwa index.php in head section i have added <link rel="manifest" href="manifest.webmanifest"> end of the page this <script> document.getElementById('loginForm').addEventListener('submit', function(event) { if (document.getElementById('remember').checked) { document.cookie = "user_login=true; SameSite=Lax; Secure"; document.cookie = "userpassword=true; SameSite=Lax; Secure"; } }); </script> manifest.webmanifest { "name": "MyPhpScript", "short_name": "PHP", "start_url": "/myscript/Dashboard.php", "display": "standalone", "background_color": "#ffffff", "theme_color": "#007bff", "icons": [ { "src": "icon-192.png", "sizes": "192x192", "type": "image/png" }, { "src": "icon-512.png", "sizes": "512x512", "type": "image/png" } ], "screenshots": [ { "src": "img.jpg", "sizes": "640x320", "type": "image/jpg", "form_factor": "wide", "label": "MyPhpScript" }, { "src": "img.jpg", "sizes": "640x320", "type": "image/jpg", "form_factor": "narrow", "label": "MyPhpScript" } ] } service-worker.js 'use strict'; /** * Received push */ self.addEventListener('install', function(event) { event.waitUntil( caches.open('my-cache').then(function(cache) { return cache.addAll([ '/script/', '/script/index.php', '/script/app.js' /** * here goes all my css and js files */ ]); }) ); }); self.addEventListener('fetch', function(event) { event.respondWith( caches.match(event.request).then(function(response) { return response || fetch(event.request); }) ); }); self.addEventListener('activate', function (event) { // The service worker is now Active and functioning. console.log("sw Activate : ", JSON.stringify(event)); // Again, ensure that this is the only active service worker for this // page. event.waitUntil(self.clients.claim()); console.log("sw Activated: ", JSON.stringify(event)); navigator.serviceWorker }); self.addEventListener('push', function (event) { let pushMessageJSON = event.data.json(); let vibratePattern = pushMessageJSON.data && pushMessageJSON.data.vibrate ? pushMessageJSON.data.vibrate : [200, 100, 200]; self.registration.showNotification(pushMessageJSON.title, { body: pushMessageJSON.body, icon: pushMessageJSON.icon, vibrate: vibratePattern, data: { additionalData: pushMessageJSON.data ? pushMessageJSON.data.additionalData : null, url: pushMessageJSON.data ? pushMessageJSON.data.url : null, }, }); console.info("pushmessage::", event); }); /** * Click by push */ self.addEventListener('notificationclick', function(event) { let url = event.notification.data.url; event.notification.close(); // Android needs explicit close. if (!url) return; event.waitUntil( clients.matchAll({type: 'window'}).then( windowClients => { // Check if there is already a window/tab open with the target URL for (var i = 0; i < windowClients.length; i++) { var client = windowClients[i]; // If so, just focus it. if (client.url === url && 'focus' in client) { return client.focus(); } } // If not, then open the target URL in a new window/tab. if (clients.openWindow) { return clients.openWindow(url); } }) ); }); self.addEventListener('message', function (event) { // A message has been sent to this service worker. console.log("sw Handling message event:", event); }); self.addEventListener('pushsubscriptionchange', function (event) { // The Push subscription ID has changed. The App should send this // information back to the App Server. console.log("sw Push Subscription Change", event); event.waitUntil( self.clients.matchAll() .then(clientList => { let sent = false; console.debug("Service worker found clients", JSON.stringify(clients)); clientList.forEach(client => { console.debug("Service worker sending to client...", client); sent = true; client.postMessage({'type': 'update'}); }); if (sent == false) { throw new Error("No valid client to send to."); } }) .catch(err => { console.error("Service worker couldn't send message: ", err); }) ); }); in footer.php <script> if (!Notification) { console.log('*Browser does not support Web Notification'); } if ('serviceWorker' in navigator) { // Register a service worker hosted at the root of the // site using the default scope. navigator.serviceWorker.register('service-worker.js', { scope: './' }).then(function(registration) { console.log('Service worker registration succeeded:', registration); }, /*catch*/ function(error) { console.log('Service worker registration failed:', error); }); } else { console.log('Service workers are not supported.'); } navigator.serviceWorker.ready.then((reg) => { const subscribeOptions = { userVisibleOnly: true, applicationServerKey: 'xyz.......' }; reg.pushManager.subscribe(subscribeOptions).then((subscription) => { // Send subscription to server fetch('save_subscription.php', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(subscription) }).then((response) => { if (response.ok) { console.log('Subscription saved successfully.'); } else { console.error('Failed to save subscription.'); } }); }).catch((error) => { console.error('Failed to subscribe:', error); }); }); </script> Push notification i am using Web-push-php from git. Everything is working fine but i want to keep pwa logged in until i manually logs out.
-
Thank you. I have corrected my code and got the result.
-
@mac_gyver : Thank you for this solution. But Why a blank page is getting added in the beginning.
-
I am trying to print multiple barcode labels at once using mpdf. There are 2 problems i am facing. 1st one : 1 blank page is getting adding at the beginning. 2nd : i want to display data like this A 1 8 instead ,it displays A 18 In TCPDF , i did not get any of these problems, but i have to use some indian language which properly displays only in Mpdf. Here is my Mpdf Code include('../includes/session.php'); require_once __DIR__ . '/bootstrap.php'; $defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults(); $fontDirs = $defaultConfig['fontDir']; $defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults(); $fontData = $defaultFontConfig['fontdata']; $mpdf = new \Mpdf\Mpdf([ 'fontDir' => array_merge($fontDirs, [__DIR__]), 'fontdata' => $fontData + [ 'freeserif' => [ 'R' => 'assets/FreeSerif.ttf', ], 'inkfree' => [ 'R' => 'assets/Inkfree.ttf', ], ], 'margin_left' => 1, 'margin_right' => 1, 'margin_top' => 1, 'margin_bottom' => 1, 'margin_header' => 1, 'margin_footer' => 1, 'showBarcodeNumbers' => TRUE ]); $sec1 = $con->prepare("SELECT bc.bc_id, bc.book_id, bc.depts, bc.dept_ids, bc.bcode_unq, bk.bk_name, bk.price, bk.currency, l.lang_name, ed.ed_dept, ed.short_code, eds.sub_dept, eds.short_code AS edssortcode FROM books_copy bc INNER JOIN books bk ON bc.book_id=bk.book_id INNER JOIN languages l ON bk.lang=l.lang_id INNER JOIN edu_dept ed ON bk.edu_dept=ed.ed_id INNER JOIN edu_subdept eds ON bk.edu_subdept=eds.eds_id WHERE bc.bc_id BETWEEN 53 AND 55"); $sec1->execute(); foreach($sec1 as $r1) { $agam = $r1['bc_id']; $bname = $r1['bk_name']; $price = $r1['price']; $lang = $r1['lang_name']; $edept = $r1['ed_dept']; $esubdept = $r1['sub_dept']; $escode = $r1['short_code']; $esscode = $r1['edssortcode']; $bcode = $r1['bcode_unq']; $dept_code = substr($r1['depts'],0,3); $deptids = $r1['dept_ids']; $dept = $escode.' '.$esscode; $deptsubdept = $edept.' '.$esubdept; $bvert = substr($esscode,0,3); $content = ''; $content .= '<html> <head> <style> body { font-family: freeserif; font-size: 12px; } .line { border-right:1px solid #000; } .vertical { border-collapse: collapse; text-align: right; writing-mode: vertical-lr; text-orientation: upright; } </style> </head> <body>'; $content .= '<table border="0"> <tr> <td> <table border="0" cellpadding="2" align="left" class="line"> <tr><td colspan="3" style="font-size:12px;"><strong>'.$_SESSION['library'].'</strong></td></tr> <tr><td>Agam : '.$agam.' </td><td colspan="2" align="right">रु. '.$price.'</td></tr> <tr><td colspan="3">Vibhag : '.$deptsubdept.'</td></tr> <tr><td colspan="3">Book : '.$bname.'</td></tr> </table> </td> <td valign="top" align="right"> <table><tr><td style="font-size:12px;" class="vertical">'.$bvert.' '.$deptids.' </td> </tr></table> </td> </tr> </table> <div style="position:fixed; top: 33mm;"> <barcode code="'.$agam.'" type="C39" class="barcode" /> <div style="text-align:center;">'.$agam.'</div> </div>'; $mpdf->WriteHTML('<pagebreak sheet-size="75mm 50mm" />'); $mpdf->WriteHTML($content); } $mpdf->Output(); i am attaching the pdf file generated thru mpdf as well as tcpdf. I can post db tables structure if it helps.
-
Yes, I tried console.log() and alert() to check each line and function. In initial function it is giving at document.getElementById('MessageContainerHead').appendChild( document.getElementById('MessageContainerFoot') ); i tried doing var d= document.createElement("div"); d.classList.add("MessageContainerFoot"); document.getElementById("MessageContainerHead").appendChild(d); But from next part document.getElementById('MessageContainerFoot').show["display"] = "block"; won't work .
-
In a php script i am trying to display all messages include error, info, warning and success messages inside a <div> tag at starting of every page after <header></header> and inside <body> tag as used in WebERP. In my script, its displays above the footer which is end of the page. Here are my code Php function for message include('MiscFunctions.php'); <?php function prnMsg($Msg, $Type = 'info', $Prefix = '') { global $Messages; $Messages[] = array($Msg, $Type, $Prefix); } ?> in footer.php i have these lines to collect all the messages <?php if (isset($Messages) and count($Messages) > 0) { foreach ($Messages as $Message) { $Prefix = ''; switch ($Message[1]) { case 'error': $Class = 'error'; $Prefix = $Prefix ? $Prefix : 'ERROR' . ' ' . 'Report'; echo '<div class="alert alert-custom alert-danger fade show mb-5 ' . $Class . '" role="alert"> <div class="alert-icon"> <i class="flaticon-warning"></i> </div> <div class="alert-text"><strong>' . $Prefix . '</strong> : ' . $Message[0] . '</div> <div class="alert-close"> <button type="button" class="close" data-dismiss="alert" aria-label="Close"> <span aria-hidden="true"> <i class="ki ki-close"></i> </span> </button> </div> </div>'; break; case 'warn': case 'warning': $Class = 'warn'; $Prefix = $Prefix ? $Prefix : 'WARNING' . ' ' . 'Report'; echo '<div class="alert alert-custom alert-warning fade show mb-5 Message ' . $Class . ' noPrint" role="alert"> <div class="alert-icon"> <i class="flaticon2-warning"></i> </div> <div class="alert-text"><strong>' . $Prefix . '</strong> : ' . $Message[0] . '</div> <div class="alert-close"> <button type="button" class="close" data-dismiss="alert" aria-label="Close"> <span aria-hidden="true"> <i class="ki ki-close"></i> </span> </button> </div> </div> '; break; case 'success': $Class = 'success'; $Prefix = $Prefix ? $Prefix : 'SUCCESS' . ' ' . 'Report'; echo '<div class="alert alert-custom alert-success fade show mb-5 Message ' . $Class . ' noPrint" role="alert"> <div class="alert-icon"> <i class="flaticon-like"></i> </div> <div class="alert-text"><strong>' . $Prefix . '</strong> : ' . $Message[0] . '</div> <div class="alert-close"> <button type="button" class="close" data-dismiss="alert" aria-label="Close"> <span aria-hidden="true"> <i class="ki ki-close"></i> </span> </button> </div> </div> '; break; case 'info': default: $Prefix = $Prefix ? $Prefix : 'INFORMATION' . ' ' . 'Message'; $Class = 'info'; echo '<div id="MessageContainerFoot"> <div class="Message ', $Class, ' noPrint"> <span class="MessageCloseButton">×</span> <b>', $Message[2], '</b> : ', $Message[0], ' </div> </div>'; } } } ?> <footer class="content-footer footer bg-footer-theme bg-dark">---- </footer> To display messages on top of the page i append messages from footer to header i have - MiscFunctions.js function initial() { document.getElementById('MessageContainerHead').appendChild( document.getElementById('MessageContainerFoot') ); document.getElementById('MessageContainerFoot').style["display"] = "block"; var close = document.getElementsByClassName("MessageCloseButton"); var i; for (i = 0; i < close.length; i++) { close[i].onclick = function(){ var div = this.parentElement; div.style.opacity = "0"; setTimeout(function(){ div.style.display = "none"; }, 600); } } } window.onload=initial; in css i have a line #MessageContainerFoot { display: none; } initial function is called like this <body onLoad="initial();"> After body tag i use <div id="MessageContainerHead"></div> to display message. In any page if i call prnMsg function like this prnMsg('The account name already exists in the database','error'); message displays in footer area/ end of the page. it is not getting displayed in <div id="MessageContainerHead"></div> i am not getting what is wrong. Can somebody help
-
Sending emails to multiple email ids with nested loop
mythri replied to mythri's topic in PHP Coding Help
Thank you @mac_gyver I tried like this and it worked as i wanted. $ven = implode(',', $_POST['vendor']); $vw = $con->prepare("SELECT email FROM ven_contacts WHERE vendor IN ($ven)"); $vw->execute(); while ($email = $vw->fetchAll(PDO::FETCH_COLUMN)) { $output1 = implode(',', $email); $to = '"'.$output1.'"'; $subject = "Email to multiple vendors"; $message = "<p>Hello All</p>"; $message .= "<p>Welcome to our Portal</p>"; $message .= "<p>Thank you</p>"; $headers = ""; $header = "From:info@mydomain.com \r\n"; $headers .= "From: Info <info@mydomain.com> \r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html\r\n"; $retval = mail ($to,$subject,$message,$headers); -
I am trying to send email from multiple email addresses using mail() function and it is working fine. But email ids are coming from database as array. Here is my code if(isset($_POST['Submit'])) { foreach($_POST['vendor'] as $k) //$_POST['vendor'] will be having multiple vendor ids { $vw = $con->prepare("SELECT email FROM ven_contacts WHERE vendor=?"); //getting all the email ids of vendors $vw->execute([$k]); foreach($vw as $ems) { $output = $ems; echo implode(', ', $output); } } When i echo $output it shows each email id 2 times for eg: abc@abc.com, abc@abc.comxyz@xyz.com, xyz@xyz.com So my email script doesn't work. if try to get $output outside the loop like this foreach($vw as $ems) { $output = $ems; } echo implode(', ', $output); } still the same problem. I want email ids to be abc@abc.com, xyz@xyz.com Then only my email script $to = $emailids; $subject = "Email to multiple vendors"; $message = "<p>Hello All"; $message .= "Welcome to our Portal"; $message .= "Thank you"; $headers = ""; $header = "From:info@mydomain.com \r\n"; $headers .= "From: Info <info@mydomain.com> \r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html\r\n"; $retval = mail ($to,$subject,$message,$headers); This email script works if i put email ids directly like this mail("abc@abc.com, xyz@xyz.com",$subject, $message, $headers); Can somebody suggest me how to get the array outside the loop
-
I got it resolved!
-
I am uploading json files to my directory called upload/source and the file name in database. When i click on edit, the json file should open in textarea or or in any editor so that i can edit the contents and save. my json file is like this src.json { "sources": [ { "id": "1", "event": "labels", "display": "Label Settings", "resultevent": "printthis" } ] } i got the file contents into textarea to edit something like this <form name="123" action="" method="post"> <table class="table m-0"> <tbody> <?php $l1 = $con->prepare("SELECT sid, src_name FROM sources WHERE sid=?"); $l1->execute([1]); foreach($l1 as $r1) { $file = "uploads/sources/".$r1['src_name']; //Path to your *.txt file $contents = file($file); $string = implode($contents); ?> <tr> <td><?php echo $r1['src_name']; ?></td> <td><textarea name="file"><?php echo $string; ?></textarea></td> <input type="hidden" name="id" value="<?php echo $r1['sid']; ?>" /> </tr> <?php } ?> <tr><td colspan="2"><input type="submit" name="save" class="btn" /></td></tr> </tbody> </table> </form> But i am not getting how to save the edited contents as src.json(same name) . Can somebody suggest me how to do it
-
I am developing a script in which i will be publishing topics to MQTT server and also when i receive the message , i submit few data to database too. I have copied and the files from MQTT client in E drive as in here , and i have pasted it in my local root directory www/phpmqtt. but i am not getting how run this subscribe.php under examples folder. I tried running it like this - http://phpmqtt/examples/subscribe.php. It shows data from phpMQTT.php messages, but doent shows what is there in subscribe.php. How to run this? Please somebody suggest me. And also where and how do i define topics? Please help me out
-
Yeassss! Thank you very much.
-
Not able to display the result to end-user as requested format in table form. Here are my tables maintab table contains, dataset contains, Now , user needs a display like this Here Result and Method name(m1,m2...) are static. I tried like this $sel = $con->prepare("SELECT m.id, m.edate, m.result, d.nos FROM maintab m INNER JOIN dataset d ON m.id=d.mid"); $sel->execute(); <table class="table"> <tr> <th></th> <th>Result</th> <th>m1</th> <th>m2</th> <th>m3</th> <th>m4</th> <th>m5</th> <th>m6</th> <th>m7</th> <th>m8</th> <th>m9</th> <th>m10</th> </tr> <?php foreach($sel as $r1) { ?> <tr> <td><?php echo date('d-m-Y', strtotime($r1['edate'])); ?></td> <td><?php echo $r1['result']; ?></td> <td><?php echo $r1['nos']; ?></td> </tr> <?php } ?> </table> Couldn't achieve the desired display. I got something like this Not getting where exactly i need to break <td> or i need to change my query. Can somebody please suggest?
-
No i tried it. With the same code above, i used header("location:".BASE_URL."/".$right_path); But page content wont open. it says even i have used exit(); after header(), but it didn't.