PDA

View Full Version : Adding security token to custom .php using a .js hook?


efelony
06-03-2014, 12:24 AM
Hey :)

I used a tutorial from PureVB This one (http://www.purevb.com/article/create-your-own-vbulletin-page/?doing_wp_cron=1401755458.6463730335235595703125) for creating a custom php,

the js i have hooked has a submit button to call results, when you click submit i get a security token error, is there a snippet i can add to verify?

sorry if this is the wrong area or not allowed.

kh99
06-03-2014, 07:25 AM
If your js is in a template, you can use {vb:raw bbuserinfo.securitytoken} to get the value of the security token. You'd add a parameter to your request called "securitytoken" and set it to that value. If you were using an html form, you'd add
<input type="hidden" name="securitytoken" value="{vb:raw bbuserinfo.securitytoken}" />

but if you're doing it all in js it would be different of course.

Another way to do it is to add some js to the page to set a variable which you can use later. For example, the vb headinclude template includes this:
<script type="text/javascript">
<--
...
var SECURITYTOKEN = "{vb:raw bbuserinfo.securitytoken}";
...
// -->
</script>

If you're already using the vb headinclude template on your page, you can just use the SECURITYTOKEN variable in your js.