-1

I am writing php code to track the visitors details who is visiting that web page. Now i want to write a javascript code on the pages i want to track. The javascript code will be using that php file code which i am writing to track visitors.

Can somebody please guide what should be my javascript code.

2
  • No, we cannot guide you. You haven't even stated what details you want to track, and why you would need/want to use js for it. And how would it be "using that php file code which i am writing to"? Commented Oct 17, 2014 at 5:57
  • situation is very simple i am actually making visitors tracking using php and will get ip,browser_info,demographics of visitor using php code which is written on single php page named index.php now i want to include it on different html pages which i have to track using javascript Commented Oct 17, 2014 at 6:11

1 Answer 1

0

If the PHP code is on same page then you can do something like this:

<script>
 var code = '<?php echo $server_code;?>';
</script>

If it's on another page, then you can fetch it using an Ajax request.

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

7 Comments

It is best to not dynamically generate JavaScript via inline PHP.
Why not as long as we are validating it?
I'd recommend checking this question out, especially both answers.
its on different page if i use ajax for it how i will include it on that page
@BrendanAshworth That is right in case of using JavaScript in external file. I still see no harm using this approach if the code is on same page. Thanks for sharing the question, it helped. Dear user23.., please try working with Ajax request for yourself and if you get stuck somewhere then feel free to ask here.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.