Jump to content

fj1200

Members
  • Posts

    48
  • Joined

  • Last visited

    Never

Posts posted by fj1200

  1. I originally put this under the PHP Applications forum but didn't get any replies so assume it was the wrong place - so trying again here...    (sorry - it's quite a long one.)

     

    I'm experimenting with different options for ftp and want to use my personal fave ftp tool - ncftp.  I like ncftp because it's very fast, very simple and has 12 well-documented exit codes.

     

    I want to run it from a php script and then return the exit code to a web page live report.  I've looked at exec() which works and so I'm happy with that, but how do I get the exit code?  I can do it in VBS easily and do so a fair bit, but I'm still very much learning with php.

     

    Looked at return() and exit() but not sure they are what I want.  Can anyone throw any light on this for me please or point me in the right direction?

     

    (PHP running under WAMP 1.7.0 on Windows Server 2003)

     

    Simple script is as follows (the exit code mappings are standard ncftp, btw and what I want to display on screen.):

     

    <?php
    
    $cmd = '"ncftpput" -u linktest -p linktest 192.168.0.10 / C:\wamp\www\ftp\test.txt';
    $nftp = exec($cmd,$output);
    
    if ($output == "0")    $output = ("Success");
    if ($output == "1")    $output = ("Could not connect to remote host.");
    if ($output == "2")    $output = ("Could not connect to remote host - timed out.");
    if ($output == "3")    $output = ("Transfer failed.");
    if ($output == "4")    $output = ("Transfer failed - timed out.");
    if ($output == "5")    $output = ("Directory change failed.");
    if ($output == "6")    $output = ("Directory change failed - timed out.");
    if ($output == "7")    $output = ("Malformed URL.");
    if ($output == "8")    $output = ("Usage error.");
    if ($output == "9")    $output = ("Error in login configuration file.");
    if ($output == "10")    $output = ("Library initialization failed.");
    if ($output == "11")    $output = ("Session initialization failed.");
    
    echo $output;
    
    ?>
    

     

    The idea is to display the output live in a web page.  However I just get a blank page.  The file copies perfectly, if I use "-d stdout" and pipe it to a text file it all looks good, but in the browser I just get 'Array'.

     

    If I echo $nftp I get the last line of the conversation - "221: Goodbye".

     

    Now running the above code as a function;

     

    <?php
    ...
    function nftp($server)
    {
    exec($cmd,$output);
    .. <code above> ..
    
    and then to see what's coming back at me I've added this at the end:
    
    $key = array_keys($output);
    $keys = print_r($key);
    Return $keys;
    }
    

    -  So now for a successful ftp transfer I get

     

    Array (

     

        * => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 [6] => 6 [7] => 7 [8] => 8 [9] => 9 [10] => 10 [11] => 11 [12] => 12 [13] => 13 [14] => 14 [15] => 15 [16] => 16 [17] => 17 [18] => 18 [19] => 19 [20] => 20 [21] => 21 [22] => 22 [23] => 23 [24] => 24 [25] => 25 [26] => 26 [27] => 27 [28] => 28 [29] => 29 [30] => 30 [31] => 31 [32] => 32 [33] => 33 [34] => 34 [35] => 35 [36] => 36 ) Array (

        * => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 [6] => 6 [7] => 7 [8] => 8 [9] => 9 [10] => 10 [11] => 11 [12] => 12 [13] => 13 [14] => 14 [15] => 15 [16] => 16 [17] => 17 [18] => 18 [19] => 19 [20] => 20 [21] => 21 [22] => 22 [23] => 23 [24] => 24 [25] => 25 [26] => 26 [27] => 27 [28] => 28 [29] => 29 [30] => 30 [31] => 31 [32] => 32 [33] => 33 [34] => 34 [35] => 35 [36] => 36 ) 1

     

     

    If I put a non-existent IP address :

    $server = "192.168.0.3";
    nftp($server);
    print nftp($server);
    

     

    I get:

     

    Array (

     

        * => 0 [1] => 1 ) Array (

        * => 0 [1] => 1 ) 1

     

     

    (without the bullet points, of course!)

     

    What I need are the codes '1','2,....'11' and depending on what code I get back will depend on what gets displayed.  This will be monitoring some critical servers around the country.  I have a VB script that does it but is doing my head in with 1 line that refuses to work so I want to try with php.

     

    Been playing all week, still no further on.  Any help greatly appreciated. Also 'discovered' what PEAR is all about this week, made a HUGE difference to some stuff I've been working on but no help for this project I think.

  2. Off home in a minute but has anyone used PEAR::Image_Graph with a DB back end?  I have both MySQL and SQL Server that I'd like to be able to display live manufacturing production data from without resorting to Xelcius but can't get it to pull the data.  I already have a tabular dashboard that displays summary info but if I could graph in instead that would be seriously cool here.  Sad, I know but true. 

     

    Been searching all afternoon, lots of people seem to have the same question but haven't managed to find an answer.

     

    Managed to get a test graph with static data into my dashboard and that looks great, just need the live stuff now.  Be good if you could use $_GET[] and re-use the data already pulled from the db but that doesn't seem to work.

  3. I'd always encrypt a password.  De-crypting is straight forward enough anyway.

     

    EG - encrypt using SHA1

     

    login: $SQL = "SELECT * FROM accounts WHERE username = $uname AND pword = SHA1($pword)";

     

    For SHA1 you can also use MD5 - for me it's ok but I like to be a bit different.  Part of me doesn't like the feature of being sent a lost password - I'd much prefer they sent you the reminder question or else what others do and reset the password.

  4. Don't mean to be thick but I've got to have something wrong somewhere.  None of this works...

     

    Ths barcode2.php file that calls the PEAR ext. works fine -

     

    http://<servername>/barcode2.php?NUM=9780131471498&TYP=code39&IMG=png

     

    <?php
    require_once"C:\wamp\php\PEAR\Image\Barcode.php";
    $bc = new Image_Barcode;
    $bc->draw($_GET[NUM], $_GET[TYP], $_GET[img]);
    ?>

     

    However if I try to then call that from the code below I just get an image placeholder. 

     

    <html>
    <?php
    $Shortcode = "12345";
    print ("<img src=\"barcode.php?NUM=9780131471498&TYP=code39&IMG=png\">");
    ?>
    </html>
    

     

    <html>
    <img src="barcode2.php?NUM=123&TYP=code39&IMG=png">
    </html>
    

     

    Tried with quotes, without quotes, haven't tried it backwards yet though....  :-[

     

    If I can nail this one then the next one I want to try is the graphing one, then the data grid.  These are 3 I've been looking for for ages and will make a real difference to me.

     

  5. I've tried a few things:

     

    • Adding it in directly to the top of the page as per the 1st code snippet
    • print ("<img src=\"barcode2.php&NUM='$_Shortcode'&TYP='code39'&IMG='PNG'\">"); (this just produces an image placeholder)
    • Image_Barcode::draw( ... )

     

    Various things.  I even got into trouble with wifey on Saturday night for playing with it when I'm NOT supposed to be working! 

     

    I can't do anything about the header being sent from the PEAR module - and I'm not that good at ph anyway.

  6. Just 'discovered' what PEAR is all about and really want to use it, but having trouble incorporating it into any web pages. 

     

    If I run

    <?php
    require_once("Image/Barcode.php");
    $bc = new Image_Barcode;
    $bc->draw($_GET['NUM'], $_GET['TYP'], $_GET['IMG']);
    ?>

     

    It works perfectly and I get an image.  If I try to imcorporate that into a web page I get:

     

    Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\barcode.php:2) in C:\wamp\php\PEAR\Image\Barcode.php on line 104

    ‰PNG ??? IHDR???P???2???ñãο???PLTE???ÿÿÿ¥ÙŸÝ???2IDATxœc(q Œw-qeeyæ8?3o¤Ã™ó£á̸çp&ßmateó.¡??f/ÅÚŽM?????IEND®B`‚

     

    I've looked up these errors, tried a few things but can't see a problem.  And - yes, I've had a hunt around this very forum too and yes - read the Headers thread at the top of this forum.  Still can't see it.

     

    I've tried

     

    image_barcode::draw

     

    and get the same problem.  Can anyone suggest a solution?  One of the issues is white space - that all looks ok unless I'm looking in the wrong place.  Everything works a treat except this.

     

  7. Now running the above code as a function;

     

    <?php

    ...

    function nftp($server)

    {

    exec($cmd,$output);

    .. <code above> ..

     

    and then to see what's coming back at me I've added this at the end:

     

    $key = array_keys($output);

    $keys = print_r($key);

    Return $keys;

    }

     

    -  So now for a successful ftp transfer I get

     

    Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 [6] => 6 [7] => 7 [8] => 8 [9] => 9 [10] => 10 [11] => 11 [12] => 12 [13] => 13 [14] => 14 [15] => 15 [16] => 16 [17] => 17 [18] => 18 [19] => 19 [20] => 20 [21] => 21 [22] => 22 [23] => 23 [24] => 24 [25] => 25 [26] => 26 [27] => 27 [28] => 28 [29] => 29 [30] => 30 [31] => 31 [32] => 32 [33] => 33 [34] => 34 [35] => 35 [36] => 36 ) Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 [6] => 6 [7] => 7 [8] => 8 [9] => 9 [10] => 10 [11] => 11 [12] => 12 [13] => 13 [14] => 14 [15] => 15 [16] => 16 [17] => 17 [18] => 18 [19] => 19 [20] => 20 [21] => 21 [22] => 22 [23] => 23 [24] => 24 [25] => 25 [26] => 26 [27] => 27 [28] => 28 [29] => 29 [30] => 30 [31] => 31 [32] => 32 [33] => 33 [34] => 34 [35] => 35 [36] => 36 ) 1

     

    If I put a non-existent IP address :

     

    $server = "192.168.0.3";

    nftp($server);

    print nftp($server);

     

    I get:

     

    Array ( [0] => 0 [1] => 1 ) Array ( [0] => 0 [1] => 1 ) 1

     

    (without the bullet points btw!)

     

    Been playing all afternoon, still no further on.  Any help greatly appreciated.

  8. Here's a bit more info...

     

    Simple script is as follows (the exit code mappings are standard ncftp, btw and what I want to display on screen.):

     

    <?php

     

    $cmd = '"ncftpput" -u linktest -p linktest 192.168.0.10 / C:\wamp\www\ftp\test.txt';

    $nftp = exec($cmd,$output);

     

    if ($output == "0") $output = ("Success");

    if ($output == "1") $output = ("Could not connect to remote host.");

    if ($output == "2") $output = ("Could not connect to remote host - timed out.");

    if ($output == "3") $output = ("Transfer failed.");

    if ($output == "4") $output = ("Transfer failed - timed out.");

    if ($output == "5") $output = ("Directory change failed.");

    if ($output == "6") $output = ("Directory change failed - timed out.");

    if ($output == "7") $output = ("Malformed URL.");

    if ($output == "8") $output = ("Usage error.");

    if ($output == "9") $output = ("Error in login configuration file.");

    if ($output == "10") $output = ("Library initialization failed.");

    if ($output == "11") $output = ("Session initialization failed.");

     

    echo $output;

     

    ?>

     

    The idea is to display the output live in a web page.  However I just get a blank page.  The file copies perfectly, if I use "-d stdout" and pipe it to a text file it all looks good, but in the browser I just get 'Array'. 

     

    If I echo $nftp I get the last line of the conversation - "221: Goodbye".

     

    You never know - this may help someone else too.  :0)

  9. I'm experimenting with different options for ftp and want to use my personal fave ftp tool - ncftp.  I like ncftp because it's very fast, very simple and has 11 well-documented exit codes.

     

    I want to run it from a php script and then return the exit code to a web page live report.  I've looked at exec() which works and so I'm happy with that, but how do I get the exit code?  I can do it in VBS easily and do so a fair bit, but I'm still very much learning with php.

     

    Looked at return() and exit() but not sure they are what I want.  Can anyone throw any light on this for me please or point me in the right direction?

     

    (PHP running under WAMP 1.7.0 on Windows Server 2003)

     

    Many thanks.

  10. I'm trying to modify an existing and very useful and important app I wrote a year ago that checks the presence of several servers around the country and verifies ftp is running on each every 2 minutes.  Results are displayed on a php page - if a server does down the row goes red and sends the IT guys at the site and me an email.  Ok if you're sitting in front of the monitor, but I want a graphical version for display on a large screen.  I want to display large 2 icons in each table cell, one for a ping response and one for ftp status.  for both, a value of '0' is live, '1' is down.  For ftp I'm using ncftpput as it's exit codes are well documented and I can display the reason on screen.

     

    How do I get the results into columns - say - 3 servers for one site, 4 for a 2nd and 3rd, and 2 for a 4th site so it's consistent and easy to follow?  Been hurting my head on it all morning!  I'm ok with php but this is challenging me a touch.

     

    I want something like:

     

    EXTERNAL SERVERS        |        INTERNAL SERVERS

    SITE 1    |    SITE 2          |        SITE 3    |    SITE 4

     

      x  x              x  x                          x    x            x    x

      x  x              x  x                          x    x            x    x

      x  x              x  x                                              x    x

      x  x              x  x

     

    Where X is a graphic of a light.  Pretty - but it works very well and is highly visible.  I eventually want an audible warning when 2 of the external servers go down.

     

    Each X is a different server, in 2 groups at 4 sites.

     

    At the moment, it works but I get one whole row of icons for each server.  Pages of them!  AArrgghh!

     

    Any ideas?  There's probably a simple way of doing it but I can't see it!

     

    <EDIT>

    Is there a way to make a row or icon flash?  refresh the colour every 2 seconds or something?

     

  11. I'm writing a dispatch note app, all working fine but having problems with job names coming out of a MySQL database text field with spaces in them.  So for example, "TEST JOB 001" comes out as "TEST".

     

    Had a look through this forum, tried one or two suggestions but not working.  tried all sorts of combinations with double and single quotes but still not working.  Can anyone assist?

     

    I have:

     

      echo "<option value=$SITE_ID"."."."$nt[EXPR3]"."."."$nt[EXPR2]"."."."$JOBTYPE>$nt[EXPR2]</option>";

     

    I split the option apart at insert with

     

      $JOB = explode(".",($_POST[JOBNAME]));

     

    (may not be pretty but it works well)

     

    EXPR2 - job description - is the one causing problems.  We have an internal job code (held in EXPR3) that will be meaningless to the dispatch guys and drivers so the need the description.  It's pulled out of our live SQL Server production database from a read-only view.

  12. I know exactly what you mean - I'm in the same boat but I only started php a few months ago cos I don't like asp and I needed a quick solution - so WAMP is running alongside Sharepoint and I code in php.  Wish I'd done it years ago!  Looking at js cos I have to really....

  13. Sorry - probably another thick js question - but I'm stummped.  Not been on js for long and I'm not a programmer. 

     

    I have a simple php form entering 5 fields into a MySQL db.  I now need to print off a form populated by those elements.  Printing is done by js and the page that does the db inserting has a  redirect in it.  Works ok - so far so good.....

     

    link <rel=\"alternate\" media=\"print\" HREF=\"http://servername/note.php\"> with...

     

    <script language="Javascript1.2">

    <!--

    function printpage(){

    window.print(); }

    //-->

    </script>

    <script language="javascript">

     

    However on printing the page note.php has no data on it.  I have also tried using a sql query in an includefile for the page to be printed - I do this elsewhere - but need to pass one of the original elements to it for the query to work.  I could do the MAX(id) no. query on the db but eventually it will be multi-user and MAX(id) may be a different record if 2 get entered at the same time. 

     

    Can I use $_POST data?  If so how - I can't get that to work either.  Is the js causing a problem in transfering the form elements through to the final printed form?

  14. I have a similar question to Andy17 below.  I'm fairly new to javascript.  I have a number of SQL Server-driven php pages, but need a new set.  I have 2 different sql queries dependent on a radio button selection to determine if a job being looked at is running or pre-completed - the data comes out of different tables and will populate a drop-down list.  The form is the same whichever dataset is used.  Radio buttons work fine, but I can't get the value passed to a query.  Last part of the radio buttons:

    }

    if (chosen == "Running")

    {

    $JOBTYPE = 1

    }

    else {

    $JOBTYPE = 0

    }

    }

     

    The php-bit is:

     

     

    If ($JOBTYPE == "0") $JOBQRY = ($jobselect0);

    If ($JOBTYPE == "1") $JOBQRY = ($jobselect1);

     

    while($nt=mssql_fetch_array($JOBQRY))

    {

    echo "<option value= $nt[JOB_NAME]"."$nt[JOB_DESCRIPTION]> $nt[JOB_DESCRIPTION]</option>";

    }

    echo "</select>";

     

    Does javascript get upset if I use a $ in a variable?  If I don't php won't see it. 

  15. Typical isn't it!!  Soon as I post a question I get it working!

     

    //SITE BARCODE BREAKDOWN

    $bc_site=substr($_POST[rs_barcode],0,2);

    $bc_press=substr($_POST[rs_barcode],2,2);

    $bc_reelstand=substr($_POST[rs_barcode],4,2);

    $bc_arm=substr($_POST[rs_barcode],6,2);

     

    Already tried that and it didn't work though!  I dunno - sometimes I hate computers!  The first pair were definately causing me issues - the only changes are after that, but I wasn't getting '01' in the database I was getting '10' but it's now seeing the first zero.  Can anyone suggest what I've done to make it work cos I have no idea!  :-[

  16. Hi - hope someone can save my sanity here.  I have a barcode - interleaved 2 of 5 (required as a 2nd barcode is also an industry std I 2 of 5) in the form 09010202.  It is made up of pairs if digits which I then split out in the php web page thus:

     

    //SITE BARCODE BREAKDOWN

    $bc_site=substr($_POST[rs_barcode],0,2);  <------ causing me problems!!

    $bc_press=substr($_POST[rs_barcode],3,2);

    $bc_reelstand=substr($_POST[rs_barcode],5,2);

    $bc_arm=substr($_POST[rs_barcode],7,2);

     

    The first row arrowed is causing the issue.  I need the leading zero included as it throws everything else out.  This is then inserted into a MySQL database.  All works fine except than it has started to drop the first zero.  I can cope with that in the database using the zerofill option, but in the above example I end up with $bc_press = 90 instead of 09, which then screws up my lookups for the reports.  It was working, and now it isn't.  Can anyone shed any light on it please?

  17. We had an issue over Easter that has serious health and safety implications and I have found a way to detect similar circumstances by querying our main sql server database via a sql query which I've converted into a view.  As long as the MAX() value of a column is '1' all is fine, but '2' is a big no-no!  The page refreshes every 15 seconds to keep production data up to date and so refreshes this query, but what I want to do is if the result of the above query comes back a >1 then a pop-up window appears with bgcolor='red' and warning image - UNITCONFLICT.jpeg.  The warning page itself is fine, done that and called it CONFLICT.php, but how do I call it on a db result?  I've been working on this 2 days now, but it's got to be simple.  The query runs fine, the value is returned to the page fine just can't get it to work.  I was thinking this morning - could have it loaded permanently and just change the visibility value?  Also, if possible, I'd like to be able to have a window open on all the production control desks warning the operators.

     

    OS - Windows 2000 Server / Professional.

    DB - SQL Server 2000.

    Php running under WAMP 1.7.0

  18. Here's how I do a similar thing but there may be better ways if anyone can suggest them?

     

    Get the field into a variable.  Have you got a DB query set up?

     

    field = $ORIG_DATA

    $DATA=(explode(",",$ORIG_DATA));    //Splits it into an array $DATA on the ',' delimiter

     

    I assign a named variable cos I find it easier when troubleshooting but you don't have to.  You could just use $DATA[n].

     

    $Firmware = ($DATA[0]);

    $GPS= ($DATA[1]);

    $Location = ($DATA[2]);

    $Latitude = ($DATA[3]);

    $Longitude = ($DATA[4]);

    $Speed = ($DATA[5]);

    $direction = ($DATA[6]);

    $ab = ($DATA[7]);

     

    You then simply use the $Firmware, $GPS etc wherever you need them.

  19. I'm not a programmer and learning php.  I'm modifying a simple php web app that I wrote last year that queries a MSSQL db, but on one  particular page I need to present the data in a DB collumn as a row.  I want to display a production board electronically as the current whiteboard gets defaced.  All the data is held in a db - easy enough.  The scenario is this:  Production occurs on on, say machine A that is comprised of a number of units.  Sometimes all 10 units will be used, other times, for example, only units 1,2,5 7 may be used.  In the database, the info is held in a table and referenced as a combination of machine and unit, so m/c A Unit 2 is A02 and so on.  I'm not worried about that - eay enough to split out.  I have a set of columns on the page - one for each unit - that I want to have an 'X' or change the bg_colour in the table cell if that unit is to be used and to be blank if not. So:

     

    M/C  JOB      ORDER  1  2  3  4  5  6  7  8  9  10

    A    10123  12,500  X  X  X    X  X

    A    10124  25,750  X  X  X

    B    12584  90,800  X  X  X  X  X  X  X  X  X  X

     

    All other data displays fine, I just need some help with this bit.  I'm sure an array is the way to do it and have a $UNIT[n] value.  The DB table is structured:

     

    JOB_ID  MACHINE  UNIT

    10123    A01

    10123    A02

    10123    A03

    10123    A05

    10123    A06

    10124    A01

    10124    A02

    10124    A03

    etc...

     

    Hope this is understandable!

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