FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » error while call php function in javascript?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: error while call php function in javascript? [message #173882 is a reply to message #173877] Wed, 11 May 2011 13:38 Go to previous messageGo to previous message
Gregor Kofler is currently offline  Gregor Kofler
Messages: 69
Registered: September 2010
Karma:
Member
Am 2011-05-11 14:10, Amit Prakash Pawar meinte:
>
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
>

Depends what you mean by "some wrong output". I suppose this "wrong
output" should tell you all you need. (Error reporting is activated, I
assume...)

> // 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]

How do is PHP supposed to know about a JS variable? In this case the
server-side PHP assumes that my_url is a constant, which it won't find
(and issue a warning).
You'd have to send your JS value to the server, have it processed there
and work with the response. Though it escapes me, why you'd like to
encode a URI, which is already on the page - plain and un-encoded.

[color=blue]>  alert(final_post_url);[/color]
[color=blue]>  
[/color]
> how to get correct encrypted data through java script?

It might be useful to know the differnce between server-side and
client-side scripting.


Gregor


--
http://vxweb.net
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: PHP Document
Next Topic: php unit test framework suggestions
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 05:42:16 GMT 2024

Total time taken to generate the page: 0.04328 seconds