Connecting Tech Pros Worldwide Help | Site Map

PHP Var -> Javascript VAR

  #1  
Old July 17th, 2005, 01:31 AM
127.0.0.1
Guest
 
Posts: n/a
In there any mechanism to get a server side PHP variable, into a client
side Javascript variable - without the value of the variable being
visible in a view source ?


--
Spam:newsgroup(at)craznar.com@verisign-sux-klj.com
EMail:<0110001100101110011000100111010101110010011 010110
11001010100000001100011011100100110000101111010011 011100
11000010111001000101110011000110110111101101101001 00000>
  #2  
Old July 17th, 2005, 01:31 AM
Kevin Thorpe
Guest
 
Posts: n/a

re: PHP Var -> Javascript VAR


127.0.0.1 wrote:[color=blue]
> In there any mechanism to get a server side PHP variable, into a client
> side Javascript variable - without the value of the variable being
> visible in a view source ?
>[/color]
Not easily. The usual way to pass variables like that is:
<script language="javascript">
var fred="<?php=$fred?>";
</script>
or
<input type="hidden" name="fred" value="<?php=$fred?>">
both of which are visible in the HTML source.

You could, however use an IFRAME which updates variables in the main
frame then redirects to obscure the contents. However a javascript
debugger will allow the contents of those vars to be seen.

It does beg the question as to why you need to pass obviously sensitive
information to the browser. I would try and keep such things in session
variables to avoid the round trip altogether.

  #3  
Old July 17th, 2005, 01:31 AM
127.0.0.1
Guest
 
Posts: n/a

re: PHP Var -> Javascript VAR


Kevin Thorpe wrote:
[color=blue]
> You could, however use an IFRAME which updates variables in the main
> frame then redirects to obscure the contents. However a javascript
> debugger will allow the contents of those vars to be seen.[/color]

That isn't a problem, however IFRAMES are not very portable apparently
....
[color=blue]
>
> It does beg the question as to why you need to pass obviously
> sensitive information to the browser. I would try and keep such
> things in session variables to avoid the round trip altogether.[/color]

Not sensative, more 'internal'.


--
Spam:newsgroup(at)craznar.com@verisign-sux-klj.com
EMail:<0110001100101110011000100111010101110010011 010110
11001010100000001100011011100100110000101111010011 011100
11000010111001000101110011000110110111101101101001 00000>
  #4  
Old July 17th, 2005, 01:31 AM
Louis-Philippe Huberdeau
Guest
 
Posts: n/a

re: PHP Var -> Javascript VAR


Since JavaScript is client-side, there is no real way to hode anything
from the user. You can obfuscate it, hide it in other js files. It will
stop most people, but it won't be hidden as there will always be a way
for them to see it, the file is stored in cache and can be viewed with
any text editor.

127.0.0.1 wrote:[color=blue]
> In there any mechanism to get a server side PHP variable, into a client
> side Javascript variable - without the value of the variable being
> visible in a view source ?
>
>[/color]

  #5  
Old July 17th, 2005, 01:31 AM
Don Faulkner
Guest
 
Posts: n/a

re: PHP Var -> Javascript VAR


On Monday 13 October 2003 04:38 am, 127.0.0.1 wrote:
[color=blue]
> Kevin Thorpe wrote:[color=green]
>>
>> It does beg the question as to why you need to pass obviously
>> sensitive information to the browser. I would try and keep such
>> things in session variables to avoid the round trip altogether.[/color]
>
> Not sensative, more 'internal'.[/color]

If the value isn't sensitive, then don't worry about it. The average user
isn't going to look at the javascript, and anyone (like us) who does
deserves what he gets when he plays around. :)

There are reasons to pass things down to the web page that need to be
protected. If that's the case here (and you don't need to change the value)
HMAC or similar is a good compromise. Send down the value and an HMAC of
the value with a secret you don't send. Then only accept the value back if
accompanied by a correct hash.
--
Don Faulkner, KB5WPM |
(This space | "All that is gold does not glitter."
unintentionally | "Not all those who wander are lost."
left blank) | -- J.R.R. Tolkien
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems Passing PHP var to Javascript Function Geneticus answers 7 September 8th, 2008 07:51 PM
php var with embedded LF to javascript var medaps answers 2 February 8th, 2007 09:48 PM
HELP: Reading javascript var from PHP Cirene answers 4 July 23rd, 2005 04:02 PM
JavaScript and PHP var problem Brian answers 3 July 23rd, 2005 02:16 PM
Javascript var to php script Pjotr Wedersteers answers 7 July 17th, 2005 08:15 AM