2

I am using PHP to generate a dynamic web form that uses an external (to my site) javascript file to set a hidden form input value. My form submits to my own PHP page before reposting to an external site. The external site requires this hidden value for any submission.

Many of the browser that are using my form do not have javascript enabled, so the tracking fails and I can not submit to the external site. Is there any method of executing the javascript file to get the tracking information from my php code without sending it to the clients browser?

This is a pseudo code mock up of the code that I want to handle the form's post:

if ($doPOST) {
  //Check POSTed parameters for tracking id ($tid)
  if ($tid == ''){
    //Execute external javascript to get tid
  }
  //Post form data to external site
}

I have looked around and could not find any relevant information, but if you know of a site where this is explained let me know. For clarification, I am not looking for information about to incude a javascript file client side.

Edit: This is the Javascript executed by the form. I have no power to change this script. The number 48891 is not hardcoded in the script it changes with execution:

onReady=(function(ie){var d=document;return ie?function(c){var n=d.firstChild,f=function(){try{c(n.doScroll('left'))}catch(e){setTimeout(f,10)}};f()}:/webkit|safari|khtml/i.test(navigator.userAgent)?function(c){var f=function(){/loaded|complete/.test(d.readyState)?c():setTimeout(f,10)};f()}:function(c){d.addEventListener("DOMContentLoaded",c,false)}})(/*@cc_on 1@*/);
var test_track=function(data){onReady(function(){document.getElementById('test_track').value = data.TID})}
test_track({"TID" : "488891"});
4
  • I am most curious, can you give us an example of the js you want to execute ? Commented Aug 1, 2011 at 20:36
  • I have posted the Javascript that needs to be executed. Commented Aug 1, 2011 at 21:09
  • No. If JavaScript is disabled, then JavaScript won't run. Commented Aug 1, 2011 at 21:18
  • 3
    +1 because it was a well thought out question and I don't think people should down vote just because they don't like the idea. We all have to work within constraints, this happens to be yours. Commented Aug 2, 2011 at 0:58

3 Answers 3

3

Yes, you can execute JavaScript server-side. However, it wouldn't make much sense just for a snippet, and you wouldn't be able to access the DOM. See the v8cgi project for a server side JavaScript implementation.

Just rewrite it in PHP.

Sign up to request clarification or add additional context in comments.

1 Comment

This code is hosted external to my site so I can't rewrite it. Thank you for the v8cgi reference.
2

No. If JavaScript is disabled on the clients browser you cannot get info out of the browser. I suggest you use PHP for tracking

Comments

1

If you are under time pressure (I am not saying this is a good idea), you can parse out the TID value and write it in the hidden form value 'test_track'.

You can get the content of the javascript with:

$js = file_get_contents('http://example.com/source.js');

2 Comments

The big trick is getting the script to execute so that I can obtain that value. Since the client has no javascript enabled is there a way in PHP to request the script so that I can parse it server side?
Thanks Tom, it is a hack but I'll see what happens with it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.