Jump to content


Photo

[SOLVED] Passing PHP Variables to a Java Applet


  • Please log in to reply
9 replies to this topic

#1 kvegas

kvegas
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 25 November 2008 - 11:27 PM

I'm using this code to attempt to assign a variable through php, then retrieve the variable within a java applet.  The problem is... well it doesn't seem to work.  The applet loads but it doesn't load the file.  Here's my code...

<?php
$playrom=http://maverik247.com/vnes/roms/dkong.nes;
?>

<applet name="vNES" code="vNES.class" archive="http://maverik247.com/vnes/vnes203.jar" width="512" 

height="480">
<param name="sound" value="on" />
<param name="timeemulation" value="on"/ >
<param name="fps" value="off" />
<param name="stereo" value="off" />
<param name="rom" value="<?php echo $playrom;?>" />
<param name="showsoundbuffer" value="off" />
<param name="scale" value="on" />
<param name="scanlines" value="off" />
<param name="nicesound" value="on" />
<param name="romsize" value="45056" />
</applet>

The following code DOES work, but as you can see, it doesn't allow anything but the predefined URL...

<param name="rom" value="http://maverik247.com/vnes/roms/dkong.nes" />

Can anyone help please?


Eventually, $playrom will need to get it's data from a URL such as "http://maverik247.co...game=dkong.nes" but for right now, I'm just trying to learn how to pass the variable this way.  (I figure step by step is the way to go so I don't get confused when things don't work.)

#2 DeanWhitehouse

DeanWhitehouse
  • Members
  • PipPipPip
  • Advanced Member
  • 2,527 posts
  • LocationUK

Posted 25 November 2008 - 11:45 PM

The variable value is assgined wrong
it should be in quotation marks
like so
<?php
$playrom = "http://maverik247.com/vnes/roms/dkong.nes";
?>

Read the rules http://www.phpfreaks...orum_guidelines

99.9% of my replies are correct, the other 0.1% means you asked the wrong question


#3 kvegas

kvegas
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 25 November 2008 - 11:56 PM

The variable value is assgined wrong
it should be in quotation marks
like so

<?php
$playrom = "http://maverik247.com/vnes/roms/dkong.nes";
?>


Made the change, still not working... here's the current code:

<?php
$playrom = "http://maverik247.com/vnes/roms/dkong.nes";
?>

<applet name="vNES" code="vNES.class" archive="http://maverik247.com/vnes/vnes203.jar" width="512" height="480">
<param name="sound" value="on" />
<param name="timeemulation" value="on"/ >
<param name="fps" value="off" />
<param name="stereo" value="off" />
<param name="rom" value=value="<?php echo $playrom;?>" />
<param name="showsoundbuffer" value="off" />
<param name="scale" value="on" />
<param name="scanlines" value="off" />
<param name="nicesound" value="on" />
<param name="romsize" value="45056" />
</applet>


#4 DeanWhitehouse

DeanWhitehouse
  • Members
  • PipPipPip
  • Advanced Member
  • 2,527 posts
  • LocationUK

Posted 25 November 2008 - 11:57 PM

You have value written twice
<param name="rom" value=value="<?php echo $playrom;?>" />
should be
<param name="rom" value="<?php echo $playrom;?>" />

Are you even looking at your code?
Read the rules http://www.phpfreaks...orum_guidelines

99.9% of my replies are correct, the other 0.1% means you asked the wrong question


#5 kvegas

kvegas
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 26 November 2008 - 12:08 AM

Oh gosh, sorry.  I didn't realize I'd posted the code that way.  It's a mistake I've already corrected, and it wasn't the problem sadly.  :-[

#6 DeanWhitehouse

DeanWhitehouse
  • Members
  • PipPipPip
  • Advanced Member
  • 2,527 posts
  • LocationUK

Posted 26 November 2008 - 12:09 AM

Although the PHP is working fine now, so i assume it must be the JAVA applet.
Read the rules http://www.phpfreaks...orum_guidelines

99.9% of my replies are correct, the other 0.1% means you asked the wrong question


#7 kvegas

kvegas
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 26 November 2008 - 12:13 AM

Is there possibly another way to achieve the results I'm after?

#8 Maq

Maq
  • Administrators
  • Advanced Member
  • 9,407 posts
  • LocationPennsylvania, USA

Posted 26 November 2008 - 01:06 AM

I think this is because you're trying to assign a server side variable to a client side language (applet)...  But I could be very wrong.
tjmothy
ini_set ("display_errors", "1");
error_reporting(E_ALL);

#9 DeanWhitehouse

DeanWhitehouse
  • Members
  • PipPipPip
  • Advanced Member
  • 2,527 posts
  • LocationUK

Posted 26 November 2008 - 01:08 AM

That shouldn't effect it as the PHP is producing the HTML. It might just be the applet, but as the PHP is solved. Please press the solved link at the bottom left.
Read the rules http://www.phpfreaks...orum_guidelines

99.9% of my replies are correct, the other 0.1% means you asked the wrong question


#10 Philip

Philip
  • Staff Alumni
  • Phailip
  • 4,769 posts

Posted 26 November 2008 - 02:28 AM

From the sun boards, seems they got it solved - however it looks to be the same thing you are doing (on the PHP side anyways)....

http://forums.sun.co...threadID=780050

The best way to do this is to use PARAM in the PHP/HTML where you call the Applet from, and GetParameter from inside the applet. Suppose you have to pass in a user password from the PHP/HTML code, into an applet. Perhaps you have to connect to the same database from inside the applet, that you are connected to from inside the PHP - where you collected the user's password. In this case, youll have to pass the password from the php code into the applet, if you want to connect to the database from inside the applet. Where you call the applet from the PHP / HTML code, use PARAM.

Suppose the password is stored in a php variable, 'db_pwd' :

?> // end php and use HTML

// load the applet
<applet code=TheApplet.class width=1000 height=1000>

// use php code for this one 'echo' call, and send the password value
<param name=password value=<?php echo($db_pwd);?>>

// done loading applet
</applet>

// back to php code
<?php
From inside the java class applet get the password:

//TheApplet.java
String password = getParameter("password");
Hope this helps.
Thomas Shavel






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users