Jump to content

doodmon

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

doodmon's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Screens seems to be doing the trick! I am giving each screen a unique name so I don't need to recall the PID. I can terminate and access the screen via that name. I call the screen in a pseudo terminal environment (nice little code I found online). $descriptorspec = array( 0 => array("pty", "w"), 1 => array("pty", "r"), 2 => array("pty", "r") ); $process = proc_open("TERM=xterm screen -S ".$screenname, $descriptorspec, $pipes); if (is_resource($process)) { fwrite($pipes[0], "commands in shell\r"); echo fread($pipes[1], 1024); fclose($pipes[0]); } my problem now is that if I attempt to fread() too much (ie, more than what is available in the terminal), The process hangs. I found this loop but it hangs as well: while (!feof($pipes[1])) { echo fgets($pipes[1], 1024); }
  2. Use Ajax... // Returns the correct XMLHttpRequest for the browser type function Get_XMLHttpRequest(){ var xmlHttp = null; if (window.XMLHttpRequest) { // If IE7, Mozilla, Safari, and so on: Use native object. xmlHttp = new XMLHttpRequest(); } else { if (window.ActiveXObject) { // ...otherwise, use the ActiveX control for IE5.x and IE6. xmlHttp = new ActiveXObject('MSXML2.XMLHTTP.3.0'); } } return xmlHttp; } function load_image(){ var xmlhttp = Get_XMLHttpRequest(); xmlhttp.open("POST","path/to/myphpfile.php",false); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.send(null); var response = xmlhttp.responseXML.documentElement; document.form.element1.value = response.getElementsByTagName('imagestring1')[0].firstChild.data; document.form.element2.value = response.getElementsByTagName('imagestring2')[0].firstChild.data; } PHP FILE: <?php header('Content-Type: text/xml'); echo '<?xml version="1.0" encoding="ISO-8859-1"?>'; ?> <response> <imagestring1><![CDATA[ this text can contain html ]]></imagestring1> <imagestring2><![CDATA[ this text can contain html ]]></imagestring2> </response> When using CDATA there cannot be spaces between the parent and the data ie this would not work: <imagestring1> <![[CDATA this won't work in firefox but does in IE6 ]]> </imagestring1> you can also return plain text in your myphpfile.php in which case javascript will contain the data in the variable xmlhttp.responseText as opposed to the responseXML: <?php echo "this is plain text or html formatted text" ?> your javascript code would need some little changes: var response = xmlhttp.responseXML.documentElement; // this line isn't necessary when dealing with text this line: document.form.element1.value = response.getElementsByTagName('imagestring1')[0].firstChild.data; should become: document.form.element1.value = xmlhttp.responseText; problem is you cannot return more than one chunk of code (ie you can't populate two or more elements at the same time as you can do with XML format). I recommend XML with CDATA if you need to pass HTML and more than one chunk at a time. finally you can use PHP $_REQUEST['variable'] and $_POST['variable'] to obtain variables passed from javascript if necessary. This can be done by modifying this line: xmlhttp.send(null); to send whatever variables you want, ie: xmlhttp.send("variable="+var1); If you are storing these images in a database, you can use PHP to access that database so the data is never hard coded.. it's good practice fun stuff
  3. Hi, I'm probably in over my head but it seems like there should be a solution to my problem. I know you can create socket connections to remote locations. In these socket connections you can input data and the process will execute it without suspending the rest of your php script. I need to perform something similar, only locally. I'm looking for a method of emulating a terminal which my php code will enter commands into while analyzing the output and, depending on what is received, will input other commands. More specifically... I am using Expect Dislocate to sustain a telnet connection to a remote location which I will constantly be feeding commands. I need to first call 'dislocate telnet' which opens a telnet session with the ability for my php server to loose connectivity and regain it later (as long as I obtain the PID which is simple enough). When I use shell_exec('dislocate telnet') or simply exec('dislocate telnet') these hang because the telnet prompt is called. If I attempt to run it in the background : exec('dislocate telnet &') I don't have a way of inputting to the telnet session I just started! I've looked at phpTelnet sockets which work great, but my need is to be able to sustain a connection between different php pages (my understanding is that a socket is closed when the php script which opened the socket has finished executing). Is there a way to separate an xterm-like console from my php script while inputting and reading from it freely?
  4. Thanks dood... glad you could help without sounding snotty
  5. So long as I create new records sequentially it will put them in order, but when i delete a record and then try to add a record it will place the new record in the old record's place. I want it to appear at the end of the table, not in the middle. Here is the code to create a new record and remove a record, can I do a sort by the number column after a new one is inserted or other suggestions??: case "create": //pretty basic, just counts the number of rows and puts record with number 1 greater than that in. //problem is it doesn't always put it at the end of the table. $vtip = isset($_POST['vtip']) ? trim($_POST['vtip']) : ""; $vtip = str_replace("'", "&rsquo;", $vtip); $db=mysql_connect ("localhost", "xxx", "xxx") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("tips"); $query = mysql_query("SELECT * FROM tips.new"); $x = mysql_num_rows($query); $x++; mysql_query("INSERT INTO new (number, tip) VALUES ('$x','$vtip')"); echo "Entry Successful"; mysql_close($db); break; case "delete": //$num is the record number being deleted. //After it is removed while loop renumbers all the records that fell after the record so there is no gap. $num = isset($_REQUEST['num']) ? trim($_REQUEST['num']) : ""; $db=mysql_connect ("localhost", "xxx", "xxx") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("tips"); mysql_query("DELETE FROM new WHERE number='$num'"); $x=0; $query = mysql_query("SELECT * FROM new"); $numrows = mysql_num_rows($query); while ($row = mysql_fetch_array($query)) { $x++; mysql_query("UPDATE new SET number='$x' WHERE number='$row[0]'"); } echo "Deletion Successful"; mysql_close($db); break;
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.