PDA

View Full Version : PHP + XHTML Help Please! :)



WAP Coder
07-18-2005, 07:50 AM
Hi. I'm creating a small web page for my mobile phone (Motorola A630) designed to turn on a small LED controlled by the parallel port. The code for normal HTML works great and easily controls the light. The working example can be found at the following address:

http://216.196.131.235/index.php

I'm not that good at working with XHTML, so I'd like some help on getting the code to with my mobile phone. When the page is accessed with the phone, it displays the following...

______________________
| Light Control .|
| .|
| " method="POST"> .|
| [On button] [Off button] .|
| .|
|_____________________.|

It appears as if the "POST" method is displaying as normal text, and when you try to use the buttons, they are not functional.

Here is the code being used in the perfectly working http://216.196.131.235/index.php page.....


<?php
{
if (isset($_POST['On']))
system("lptout 255");
system("lptout 255");
}
if (isset($_POST['right']))
{
system("lptout 128");
system("lptout 128");
}
if (isset($_POST['down']))
{
system("lptout 64");
system("lptout 64");
}
if (isset($_POST['Off']))
{
system("lptout 0");
system("lptout 0");
}
?>
<HTML>
<HEAD><TITLE>Light controls</TITLE></HEAD>
<BODY>
<h2>Light Control</h2><br>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
<INPUT type='submit' name='On' value="On">

<INPUT type='submit' name='Off' value='Off'>


Here is the code being used for the non-functioning XHTML version...



<?php
{
if (isset($_POST['On']))
system("lptout 255");
system("lptout 255");
}
if (isset($_POST['right']))
{
system("lptout 128");
system("lptout 128");
}
if (isset($_POST['down']))
{
system("lptout 64");
system("lptout 64");
}
if (isset($_POST['Off']))
{
system("lptout 0");
system("lptout 0");
}


?>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<HEAD><TITLE>webcam controls</TITLE></HEAD>
<BODY>
<h2>Light Control</h2><br>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
<INPUT type='submit' name='On' value="On">

<INPUT type='submit' name='Off' value='Off'>
</html>


I don't see why it wouldn't be working. It is being hosted on my Apache server, just to let you know.

Any help would be greatly appreciate as I've been up all night trying to get this working and I'd really like to get it done by tomorrow.

Thanks!

mwinter
07-18-2005, 01:24 PM
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<HEAD><TITLE>webcam controls</TITLE></HEAD>
<BODY>
<h2>Light Control</h2><br>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
<INPUT type='submit' name='On' value="On">

<INPUT type='submit' name='Off' value='Off'>
</html>If your mobile has a conforming XML parser, it will choke on that markup as it isn't well-formed. Experiment with the following:


<?php
if(!empty($_POST['control'])) {
if('On' == $_POST['control']) {
system('lptout 255');
system('lptout 255');
} elseif('Off' == $_POST['control']) {
system('lptout 0');
system('lptout 0');
}
}
?>
<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Webcam Controls</title>
</head>

<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset><legend>Light controls</legend>
<input type="submit" name="control" value="On" />
<input type="submit" name="control" value="Off" />
</fieldset>
</form>
</body>
</html>Hope that helps,
Mike

WAP Coder
07-18-2005, 07:04 PM
Thanks for your help! Unfortunately, it is still doing the same thing..

Here is a picture of what it looks like on the phone:

http://216.196.131.235/phone2.JPG

Twey
07-18-2005, 07:45 PM
For a start...
<?php echo $_SERVER['PHP_SELF'];?>
can be replaced with
<?=$PHP_SELF?>

<?=value?> is shorthand for "<?php echo(value); ?>", and $PHP_SELF is an automatic global which is the same as $_SERVER['PHP_SELF']. It has several aliases.
This is where the problem seems to be occurring. See if the page works if you replace the PHP echo with the literal page name
(<form action="index.php" method="post">). If it does, then the PHP is outputting something it shouldn't be.

mwinter
07-18-2005, 08:14 PM
For a start...
<?php echo $_SERVER['PHP_SELF'];?>
can be replaced with
<?=$PHP_SELF?>Yes, one could, but I certainly prefer not to. I do like the more compact form, but I don't like to use features that could end up being disabled.


<?=value?> is shorthand for "<?php echo(value); ?>",I never use short_open_tag (nor asp_tags), and my test server is configured not to support them.


and $PHP_SELF is an automatic global which is the same as $_SERVER['PHP_SELF'].The same goes for register_globals.


This is where the problem seems to be occurring.It does, but I assume that the OP is directing the device to the URL in the first post, in which case it can't be the problem.

To the OP: If you aren't (you're attempting to view a different URL), can you please post either that URL, or the source as seen by your mobile. Don't post the server-side code - the output is more important for the moment.

Mike

WAP Coder
07-19-2005, 12:37 AM
The page I am directing my mobile phone to is test.xhtml.

I have no way of viewing the source on my phone. :( When I replace
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> with
<form action="test.xhtml" method="post"> the unwanted text goes away and the page appears as desired, but doesn't function correctly. If you would like to see the page on your own mobile phone or with an emulator, go to
http://216.196.131.235/test.xhtml .

I still don't know why it isn't working. :mad:

mwinter
07-25-2005, 12:33 AM
It's probably become obvious by now, but I'll say it anyway: I'm stumped. I can't see any explanation for this phenomenon. Have you tried contacting Motorola Technical Support? I can only assume a fault in their software, unless there's some aspect of WAP 2.0 that I'm missing.

Mike

WAP Coder
07-25-2005, 04:53 AM
I haven't tried contacting Motorola. I think I'm just going to use WAP 1.0 and skip all the XHTML. :D Thanks for all your help though guys! This is a great forum.

mikice992
07-30-2005, 12:37 PM
the line:
<?xml version="1.0" encoding="UTF-8"?>
needs to be changed to
<?php echo "<?xml version='1.0' encoding='UTF-8' ?>"; ?>
you need to do this because when the PHP parser parses that line, it gets confused and weird things can be sent to the browser. This isn't guarenteed to fix your problem, but I noticed that I have problems with my PHP files if that isn't in an echo. I hope it works, good luck...

Twey
07-30-2005, 01:11 PM
Aaahhh, nice thinking. That will probably help.

mwinter
07-30-2005, 02:23 PM
the line:
<?xml version="1.0" encoding="UTF-8"?>
needs to be changed to
<?php echo "<?xml version='1.0' encoding='UTF-8' ?>"; ?>
you need to do this because when the PHP parser parses that line, it gets confused and weird things can be sent to the browser.It's a nice thought, but it's not an issue. If the short_open_tag option is active, an XML prolog will be seen as a parse error. This wouldn't cause "weird things" to be sent to the browser: nothing would be.

As things stand, short_open_tag must be off, and this still remains a problem with the user agent.

Mike