Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #1519

Re: error while call php function in javascript?

From Gregor Kofler <usenet@gregorkofler.com>
Newsgroups comp.lang.php
Subject Re: error while call php function in javascript?
Date 2011-05-11 15:38 +0200
Organization A noiseless patient Spider
Message-ID <iqe3fv$d7i$1@dont-email.me> (permalink)
References <3ece3c5d-94b1-4fea-9af7-08657b1eaae5@d19g2000prh.googlegroups.com>

Show all headers | View raw


Am 2011-05-11 14:10, Amit Prakash Pawar meinte:
> [code]function encrypt_url($string)
> {
> 	$key = "1AT2#mr(luv^iU3tp>";
> 	$result = '';
> 	for($i=0; $i<strlen($string); $i++)
> 	{
> 		$char = substr($string, $i, 1);
> 		$keychar = substr($key, ($i % strlen($key))-1, 1);
> 		$char = chr(ord($char)+ord($keychar));
> 		$result.=$char;
> 	}
> 	return urlencode(base64_encode($result));
> }[/code]
> 
> $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
> [code]
> var my_url=document.getElementById('url').value;
> 
> // my_url='http://www.test.com';
> 
> var final_post_url=<?=encrypt_url(my_url)?>;

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.

> alert(final_post_url);
> [/code]
> 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

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

error while call php function in javascript? Amit Prakash Pawar <amitppawar2007@gmail.com> - 2011-05-11 05:10 -0700
  Re: error while call php function in javascript? Tim Streater <timstreater@waitrose.com> - 2011-05-11 14:30 +0100
  Re: error while call php function in javascript? Gregor Kofler <usenet@gregorkofler.com> - 2011-05-11 15:38 +0200
  Re: error while call php function in javascript? Jeff North <jnorthau@yahoo.com.au> - 2011-05-11 23:51 +1000
    Re: error while call php function in javascript? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-05-11 16:31 +0200

csiph-web