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));
}

$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

var my_url=document.getElementById('url').value;

// my_url='http://www.test.com';

var final_post_url=<?=encrypt_url(my_url)?>;
alert(final_post_url);

plz help me how to get correct encrypted data through java script?

You can't (normally) access javascript variables form php. You'll need to write that function in javascript, and call that function.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.