PHP Var -> Javascript VAR

This is a discussion on PHP Var -> Javascript VAR within the PHP Language forums, part of the PHP Programming Forums category; In there any mechanism to get a server side PHP variable, into a client side Javascript variable - without the value ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-13-2003
127.0.0.1
 
Posts: n/a
Default PHP Var -> Javascript VAR

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>
Reply With Quote
  #2 (permalink)  
Old 10-13-2003
Kevin Thorpe
 
Posts: n/a
Default Re: PHP Var -> Javascript VAR

127.0.0.1 wrote:
> 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 ?
>

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.

Reply With Quote
  #3 (permalink)  
Old 10-13-2003
127.0.0.1
 
Posts: n/a
Default Re: PHP Var -> Javascript VAR

Kevin Thorpe wrote:

> 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.


That isn't a problem, however IFRAMES are not very portable apparently
....

>
> 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.


Not sensative, more 'internal'.


--
Spam:newsgroup(at)craznar.com@verisign-sux-klj.com
EMail:<0110001100101110011000100111010101110010011 010110
11001010100000001100011011100100110000101111010011 011100
11000010111001000101110011000110110111101101101001 00000>
Reply With Quote
  #4 (permalink)  
Old 10-13-2003
Louis-Philippe Huberdeau
 
Posts: n/a
Default 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:
> 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 ?
>
>


Reply With Quote
  #5 (permalink)  
Old 10-14-2003
Don Faulkner
 
Posts: n/a
Default Re: PHP Var -> Javascript VAR

On Monday 13 October 2003 04:38 am, 127.0.0.1 wrote:

> Kevin Thorpe wrote:
>>
>> 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.

>
> Not sensative, more 'internal'.


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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:31 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0