Re: error while call php function in javascript? [message #173883 is a reply to message #173877] |
Wed, 11 May 2011 13:51 |
Jeff North
Messages: 58 Registered: November 2010
Karma:
|
Member |
|
|
On Wed, 11 May 2011 05:10:57 -0700 (PDT), in comp.lang.php Amit
Prakash Pawar <amitppawar2007(at)gmail(dot)com>
<3ece3c5d-94b1-4fea-9af7-08657b1eaae5(at)d19g2000prh(dot)googlegroups(dot)com>
wrote:
> | function encrypt_url($string)[/color]
[color=blue]> | {[/color]
[color=blue]> | $key = "1AT2#mr(luv^iU3tp>";[/color]
[color=blue]> | $result = '';[/color]
[color=blue]> | for($i=0; $i<strlen($string); $i++)[/color]
[color=blue]> | {[/color]
[color=blue]> | $char = substr($string, $i, 1);[/color]
[color=blue]> | $keychar = substr($key, ($i % strlen($key))-1, 1);[/color]
[color=blue]> | $char = chr(ord($char)+ord($keychar));[/color]
[color=blue]> | $result.=$char;[/color]
[color=blue]> | }[/color]
[color=blue]> | return urlencode(base64_encode($result));[/color]
[color=blue]> | } [/color]
> |
> | $data=encrypt_url('http://www.test.com');
> | Normally through PHP code i got encrypted value ->
> | pqW1xGxSnOmf46Pqw9zJYdffqw%3D%3D
> |
> | When i try through javascript getting some wrong output
> |
> | // Javascript
> | [/color]
[color=blue]> | var my_url=document.getElementById('url').value;[/color]
[color=blue]> | [/color]
[color=blue]> | // my_url='http://www.test.com';[/color]
[color=blue]> | [/color]
[color=blue]> | var final_post_url=<?=encrypt_url(my_url)?>;[/color]
[color=blue]> | alert(final_post_url);[/color]
[color=blue]> | [/color]
> | how to get correct encrypted data through java script?
try (note the quotes placement:
var final_post_url="<?=encrypt_url(my_url)?>";
|
|
|