Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: PHP + XHTML Help Please! :)

  1. #1
    Join Date
    Jul 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default PHP + XHTML Help Please! :)

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

    Code:
    <?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...

    Code:
    <?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!

  2. #2
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by WAP Coder
    Code:
    <?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 Code:
    <?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

  3. #3
    Join Date
    Jul 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for your help! Unfortunately, it is still doing the same thing..

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

    Last edited by WAP Coder; 07-18-2005 at 06:12 PM.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey
    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

  6. #6
    Join Date
    Jul 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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
    Code:
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    with
    Code:
    <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.

  7. #7
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

  8. #8
    Join Date
    Jul 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I haven't tried contacting Motorola. I think I'm just going to use WAP 1.0 and skip all the XHTML. Thanks for all your help though guys! This is a great forum.

  9. #9
    Join Date
    Jul 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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...
    Last edited by mikice992; 07-30-2005 at 11:46 AM.

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Aaahhh, nice thinking. That will probably help.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •