Note that there are some explanatory texts on larger screens.

plurals
  1. POLearning PHP - Is there a better way to do this?
    primarykey
    data
    text
    <p>I'm a new learner of PHP. I have written the following two files which do seem to work.</p> <ol> <li>I'd like to know if I can achieve the effect with just one script.</li> <li>I'd like to know if there's a better way to do this.</li> <li>The dox.php has to redirect to index.php every time, can I do away with the redirection?</li> </ol> <p>To summarize the content of both files in words: Index.php creates a page with 8 images on it. All these 8 images have alternate versions which indicate that the image/button is active or not. Click on the button and the action is performed, click on it again and the action performed is reversed. (XOR function is used) - The current condition of the image/button is dictated by an external variable. (kind of like a feedback system)</p> <h2>Contents of: index.php</h2> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt; &lt;html&gt;&lt;head&gt; &lt;link rel="stylesheet" type="text/css" href="style2.css" /&gt; &lt;meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"&gt; &lt;title&gt;Project ARC: Adeel's Room Controller&lt;/title&gt; &lt;/head&gt;&lt;body&gt; &lt;h1&gt;Welcome to Project ARC&lt;/h1&gt; &lt;?php $curx_val=shell_exec('sudo pin 0x378'); $curx_val=decbin($curx_val); $curx_val=str_pad($curx_val,8,0,STR_PAD_LEFT); //echo "$curx_val"; $bit_array=str_split($curx_val,1); //echo "$bit_array[7]"; echo '&lt;a href="dox.php?setvalue=128"&gt;&lt;img style="border: 0px solid ; width: 20px; height: 100px;" alt="bit0" src="images/bit' . $bit_array[0] . '.png"&gt;&lt;/a&gt; '; echo '&lt;a href="dox.php?setvalue=64"&gt;&lt;img style="border: 0px solid ; width: 20px; height: 100px;" alt="bit0" src="images/bit' . $bit_array[1] . '.png"&gt;&lt;/a&gt; '; echo '&lt;a href="dox.php?setvalue=32"&gt;&lt;img style="border: 0px solid ; width: 20px; height: 100px;" alt="bit0" src="images/bit' . $bit_array[2] . '.png"&gt;&lt;/a&gt; '; echo '&lt;a href="dox.php?setvalue=16"&gt;&lt;img style="border: 0px solid ; width: 20px; height: 100px;" alt="bit0" src="images/bit' . $bit_array[3] . '.png"&gt;&lt;/a&gt; '; echo '&lt;a href="dox.php?setvalue=8"&gt;&lt;img style="border: 0px solid ; width: 20px; height: 100px;" alt="bit0" src="images/bit' . $bit_array[4] . '.png"&gt;&lt;/a&gt; '; echo '&lt;a href="dox.php?setvalue=4"&gt;&lt;img style="border: 0px solid ; width: 20px; height: 100px;" alt="bit0" src="images/bit' . $bit_array[5] . '.png"&gt;&lt;/a&gt; '; echo '&lt;a href="dox.php?setvalue=2"&gt;&lt;img style="border: 0px solid ; width: 20px; height: 100px;" alt="bit0" src="images/bit' . $bit_array[6] . '.png"&gt;&lt;/a&gt; '; echo '&lt;a href="dox.php?setvalue=1"&gt;&lt;img style="border: 0px solid ; width: 20px; height: 100px;" alt="bit0" src="images/bit' . $bit_array[7] . '.png"&gt;&lt;/a&gt; '; ?&gt;&lt;br&gt; &lt;br&gt; &lt;/body&gt;&lt;/html&gt; </code></pre> <p>Contents of dox.php</p> <pre><code>&lt;html&gt; &lt;title&gt;PrimaryCommander&lt;/title&gt; &lt;body&gt; &lt;?php //Variable Declaration $set_val=$_REQUEST["setvalue"]; //Which light to switch on $cur_val=shell_exec('sudo pin 0x378'); //Current lights which are ON settype($set_val,"integer"); $xor_result=$set_val^$cur_val; shell_exec('sudo parashell 0x378 '.$xor_result); header( 'Location: index.php' ) ; ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Edit1: This script interfaces with the parallel port - thus the shell_exec command. The command 'sudo parashell 0x378 0' sets all pins of parallel port to 0.</p> <p>Edit2: I understand that once the page has been rendered, it cannot be changed. But can I make the page so as to reflect live changes? (Somewhat like the facebook live feed feature?)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload