I created a QR code that invokes a pure PHP page to perform database updates. I currently testing with the iPhone camera and it does trigger backend operations as expected. The question is when the QR code is scanned, it brings up a blank page. Is it possible to close this blank page by itself at the end of back-end operations or at least not to open a new blank page every time but remain on the same blank page for every new scan?
CodePudding user response:
You can use window.close() in javascript if your page is created by window.open(). Otherwise, it is not possible to close a page from client side.
If you don't want your users to see a blank page you can redirect them to another page after operation has been done. Use header function in php.
header('Location: http://localhost/');
CodePudding user response:
A QR code doesn't "invoke" anything, it encodes some text.
If you're writing a custom app, that text can be anything you like, and trigger any behaviour you like.
If the text you encode is a URL, that URL can be opened in a web browser. It will behave exactly the same as if the user had clicked a link to it, or typed it into their web browser. You have only the same control of that browser as any other website, and that doesn't include managing their tabs for them - you weren't responsible for creating the tab, so have no power to close it.
Indeed, the user can look at the URL and share it around, edit it, or be tricked into visiting it by someone else. Make sure you understand the security implications of this! You might want to make the URL load a page with a button on, which submits a POST form, which can't be bookmarked etc; read up on techniques to avoid "CSRF attacks".
What you can and should do is make the page not blank - write a "thank you" message, or redirect the user somewhere else, once the action has completed.