Howdy y'all,

Got a question, why were here right, I have a page that is server side - no html included all php - I need to call/include a javascript function to handle a rather complex parsing routine but I am not sure how I go about calling the function inside this page...the information that I need to parse is being sent as a post from a form...

As an example lets say that I have the following:

<?PHP

	//Remove dangerious and unwanted charectors from the form input
	function StripSpecChar($val) {
	return (preg_replace('/[^a-zA-Z0-9" "-.@\:\/_]/','', $val));
	}
	
	//Convert POST data field from the form to PHP Session 
	foreach ($_POST as $key => $val) { 
        $_SESSION[$key] = StripSpecChar($val);  
	}
        
        $string = $_SESSION['reader'];

        //RUN JS FUNCTION HERE AGAINST $string

        //Return true/false results here

        //Continue PHP processing here

?>

The function that I am need to run takes a data string from a magnetic strip swipe, breaks it into its parts based on landmarks in the string then I need to validate 2 sets of data in the string i.e. an employee id number and the issue date. If those pass the checks then I need to fire off the rest of the php that allows the data to be processed or error back that they need to try swiping the badge again etc...

I have both parts working as stand alone pieces but I don't know how to fuse them together...

Recommended Answers

All 3 Replies

Well for one, javascript is client side, not server side so what you're trying to do here isn't really feasible. Though I don't understand why you just don't translate it from javascript into php and have it just echo back that they need to swipe it again as the two languages are extremely similar.

Well for one, javascript is client side, not server side so what you're trying to do here isn't really feasible. Though I don't understand why you just don't translate it from javascript into php and have it just echo back that they need to swipe it again as the two languages are extremely similar.

Thanks for the feedback on this Nyight, I have considered re-writing it but as of yet I have not found a full conversion chart to work with my js knowledge is almost zero. The script was done by a former employee of mine and well honestly I don't think I can contact him for assistance.

I am considering just doing an explode on the string and developing a check of the number similar to a LUHN check since (in theory) the EmployeeID = 5 if the number is added together one digit at a time then divided by a number....just it is a beautiful script and would have liked to reuse it...

I think I will just mark this as "Solved"

Thanks again for your help!

If you need anymore help or want some help rewriting the code, toss it my way and I'll help as best I can.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.