Jump to content

Trying to convert PHP to Javascript


emma57573

Recommended Posts

I have some code that im using on my site thats works great, I want to use the same code on my PHPBB Forum but in order to run smoothly I need to covert it to javascript. However its not working so somethings wrong with my syntax. If anyone could help that would be great.

 

This is the working code

 

<?PHP
//script for the <BODY> area of your source code, transferring necessary user data
//place this script on every page if the user is logged in !!!

$tk_name = "$V3CHAT_NAME"; //<-- please set the username here
$tk_user_id = "$V3CHAT_USER"; //<-- please set the user ID here
$tk_gender = ""; //<-- optional (the gender of the user can be female or 'male')
$tk_age = ""; //<-- optional (the age of the user e.g. '23')
$tk_single = ""; //<-- optional (is the user single? 'Yes', 'no', '0' = no information)
$tk_profile_url = ""; //<-- optional (url to the users profile)
$tk_pic = ""; //<-- optional (url of the users picture)
$tk_city = ""; //<-- optional (city where the user is located, e.g. 'Berlin')
$tk_zip = ""; //<-- optional (users zip code, e.g. '92553')
$tk_country = ""; //<-- optional (country where the user is located, e.g. 'Germany')

//DO NOT EDIT THE FOLLOWING CODE!
$tk_user_data="name:".$tk_name. ";gender:".$tk_gender. ";age:".$tk_age. ";single:".$tk_single. ";url:".$tk_profile_url. ";pic:".$tk_pic. ";city:".$tk_city. ";tk_zip:".$tk_zip. ";country:".$tk_country;


//implements the js needed by the chatWatcher and to start a chat

$tk_hash = md5($tk_user_id.$tk_user_data."wcwUrTFHLbpMeV9vcnSp");
$tk_js = "<script type='text/javascript' src='http://www.toksta.com/js/w/?tk_hash=" . $tk_hash . "&app_id=87879&app_user_id=".$tk_user_id."&tk_user_data=".rawurlencode($tk_user_data)."'></script>" .
"<script type='text/javascript' src='http://www.toksta.com/js/tokstaIm/?tk_hash=" . $tk_hash . "&app_id=87879&app_user_id=".$tk_user_id."&tk_user_data=".rawurlencode($tk_user_data)."'></script>";
echo $tk_js;
?>

 

 

This is how ive converted it for phpbb. It just comes up with a java error popup

<script type='text/javascript' src='http://www.toksta.com/js/w/?tk_hash=md5("{USER_ID}".
name:"{USER_NAME}";
gender:"";
age:"";
single:"";
url:"";
pic:"";
city:"";
tk_zip:"";
country:"";
."wcwUrTFHLbpMeV9vcnSp")&app_id=87879&app_user_id="{USER_ID}"&tk_user_data=".rawurlencode(
name:"{USER_NAME}";
gender:"";
age:"";
single:"";
url:"";
pic:"";
city:"";
tk_zip:"";
country:"";
)."'>
</script>

<script type='text/javascript' src='http://www.toksta.com/js/w/?tk_hash=md5("{USER_ID}".
name:"{USER_NAME}";
gender:"";
age:"";
single:"";
url:"";
pic:"";
city:"";
tk_zip:"";
country:"";
."wcwUrTFHLbpMeV9vcnSp")&app_id=87879&app_user_id="{USER_ID}"&tk_user_data=".rawurlencode(
name:"{USER_NAME}";
gender:"";
age:"";
single:"";
url:"";
pic:"";
city:"";
tk_zip:"";
country:"";

)."'>
</script>

 

 

Link to comment
Share on other sites

NOGO.. it wont work... to set value from PHP to javascript you need to write like this...

<?php

$phpVar1="Value1";
$phpVar2="Value2";


echo "<script type='text/javascript'>";

echo "var jsVar1='$phpVar1';";
echo "var jsVar2='$phpVar2';";
echo "function someFunction() {
           alert(jsVar1);
         }";
echo "</script>";
?>

 

This above code will give this output:

 

<script type='text/javascript'>

var jsVar1='Value1';
var jsVar2='Value2';
function someFunction(){
     alert(jsVar1);
}
</script>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.