views:

67

answers:

2

Howdy y'all,

I am looking for a way to include a .js function with in a straight php page. By straight php I mean there is no html included.

Explanation of process if you will.

I have a page where employees must swipe their ID badge for access to a computer. The employee swipes the badge, the magnetic strip is read, and the data sting is sent to the db to get the access levels etc. This works great unless I get a bad card read. What I have is a .js file that pulls the ID and the issue date of the badge from the data string and validates it before going to the db. If it fails it errors. At the error point I will ask them to swipe the card again etc...

So back to the top, can I use this .js file in a php file.

If not, can someone point me to a library or chart where I can find the comparison values for js and php. (.js - var s = ""; | .php $s = ""; etc...)

+2  A: 

Can't you implement the validation logic in php:

<?php 
    function validateId($id = null) {
        // your validation code goes here
        if($id != null) {
            // Code to be executed for a successful swipe
            echo "success";
        } else {
            // Code to be executed for a failed swipe
            echo "An epic failure occurred. Please swipe again";
        }
    }
Adam
A: 

I think your best bet would be to install a server-side JS engine and then run it using system.

A reasonable example is Narwhal. If you install that on your server, then you can do something like this from PHP:

system('js /path/to/my/js/file.js',$retval);

The only thing you may have to modify is any case where your JS interacts with the browser (i.e. document.writes, DOM manipulation), but Narwhal has equivalents for interacting with the CLI.

Ryley