Jump to content

enveetee

Members
  • Posts

    32
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by enveetee

  1. I have several scripts which contain the exact same function name and accept the same number of arguments

     

    example

     

    script1.php

    <?php

    function DoThis($arg1){

    .

    .

    }

    ?>

     

    script2.php

    <?php

    function DoThis($arg1){

    .

    .

    }

    ?>

     

    script3.php

    <?php

    function DoThis($arg1){

    .

    .

    }

    ?>

     

    What syntax should I use (if indeed i can) to call each one. Is it something to do with NAMESPACE?

     

    Thanks

  2. Hi

     

    My app sends out emails.

     

    Included in the email is a link to a PDF document which can be downloaded and views.

     

    The document(s) reside in different folders on the server, only known at creation time.

     

    My app can run from the root as well as a folder

     

    How can I get the url to the file for inclusion in the email.

     

    examples are

     

    http://www.myserver.com/docs/document1.pdf

    http://www.myserver.com/document2.pdf

    http://www.myserver.com/docs/anotherfolder/document1.pdf

     

    Thanks

     

  3. Mac_gyver - thanks, very enlightening.

     

    The solution seems to be to keep sensitive files (MySQL credentials and raw uploaded files) in a folder which the server cannot access so now the question becomes:

     

    How do I access files outside of the server web root?

     

    public_html/

    /phpfiles

    /includes

    /docs

    /script

    /other

    /sensitivefiles <<<<< (my php scripts need access to the contents of this folder but a browser cannot gain access)

     

    Cheers

  4. OK, so my application is now in the Beta phase and I am rolling it out to some tame customers. I am using justhost.com for hosting using a standard Business Pro package

     

    Each one of my PHP scripts has an required_once to a PHP include which contains the MySQL login name and password details. Obviously if anyone gains access to this the game is over.

     

    Where is the best place to keep this file (I have it in ../includes)

     

    How do I stop anyone from seeing the contents

     

    Thanks

  5. I have a client application which runs a script on my server using HTTP POST

     

    How can I get a clean result of that script

     

    Currently, the script returns all sorts of headers, fonts and so on

     

    All I need is the name of the currently executing script (__file__?) and a result 1 or 0 plus any error message

     

    Suggestions please..

     

  6. Looking for some guidance on this...

     

    I have two applications, A windows desktop application written in VB6/VB.NET and my new (and learning) PHP/MYSQL app.

     

    I am mirroring records between them. Records can be added to both systems and I synchronise them.

     

    I am currently dealing with downloading the PHP/MYSQL records to my desktop and was wondering if I was going about it in the right way.

     

    This is how I have designed it...

    I have a common form which deals with three actions (POLL, DOWNLOAD and CONFIRM) using POST. I can return the number of records to be downloaded (using the POLL) paramater, the actual record (using a DOWNLOAD parameter along with a record ID) and finally a CONFIRM parameter to mark the MYSQL record as having been downloaded and is in the desktop database. I am ECHO'ing out values from the PHP form which is being received by the desktop component.

     

    This does work, but was wondering if the way I was doing it is ok - it seems too simple which scares me!

     

    Comments/advice/bullet-between-the-eyes - please

     

     

    here's the code if you are interested...

    <?php
    
    
    require_once('../includes/cs_functions.php');
    require_once('../includes/cs_password.php');
    require_once('../includes/meekrodb.2.3.class.php');
    require_once('../classes/cUser.php');
    FN_MeekroDBSetup();
    
    
    //Call as POLL first to return id's of records needed to be downloaded TAB separated
    //Whitelist the POST values into WhiteListParameter array
    $WLP = allowed_post_params(['cs_name', 'cs_password', 'cs_mode', 'cs_id', 'cs_serialno', 'cs_downloadtime']);
    
    
    //Declare the user class for user name and password validation later
    $cUser = new clsUser;
    
    
    //These are debug settings so form can be executed in Netbeans
    $WLP['cs_name'] = 'Admin';
    $WLP['cs_password'] = 'a';
    $WLP['cs_mode'] = 'POLL';
    $WLP['cs_mode'] = 'DOWNLOAD';
    $WLP['cs_mode'] = 'CONFIRM';
    
    
    
    
    //Validate user, returns NULL if user not valid
    $cUser = FN_Validate_User($WLP['cs_name'], $WLP['cs_password'], TRUE);
    
    
    if ($cUser == NULL) {
    
    
    } else {
    
    
    
    
    //Detect mode POLL, CONFIRM, DOWNLOAD
    switch ($WLP['cs_mode']) {
    
    
    case "POLL":
    //Check if any records to be downloaded and return a TAB delimited list of record ID's
    $resultsArray = db::query("SELECT * FROM bk WHERE bkwebbooking=%s AND bkwebbooking_downloadedtime=%s", '1', NULL);
    $tmp = '';
    foreach ($resultsArray as $row) {
    $tmp = $tmp . $row['id'] . chr(9);
    }
    
    
    //Loose trailing TAB
    $tmp = FN_Shorten($tmp, 1);
    break;
    
    
    case "DOWNLOAD":
    //Return the record for import into desktop system
    $resultsArray = db::query("SELECT * FROM bk WHERE id=%s", $WLP['cs_id'], NULL);
    $tmp = '';
    foreach ($resultsArray as $row) {
    $tmp = $tmp . $row['id'] . chr(9) . $row['bkaccount'] . $row['bkservice'];
    }
    break;
    case "CONFIRM":
    //Update MYSQL record with time and serial number from desktop system $cs_serialno, $cs_downloadtime
    
    
    
    
    default:
    $tmp = 'Call with POLL or DOWNLOAD or CONFIRM';
    break;
    }
    
    
    echo $tmp;
    }
    
  7. I am trying to upload a large dataset in CSV format for batch loading into a MYSQL table using LOAD DATA INFILE


     


    The CSV file (test.csv) is in


    /var/services/web/php


     


    My table is in


    /var/services/mysql/TABLENAME


     


    When I run the SQL command from a PHP script I get an error ERROR: Can't get stat of '/var/services/mysql/TABLENAME/test.csv' (Errcode: 2) Which I believe is because the file needs to be in /var/services/mysql/TABLENAME. Indeed, if I move it there, it works fine


     


    If I try and use the LOCAL switch LOAD DATA LOCAL INFILE I get an error stating that feature is not available. Research shows it can cause a security hole and needs to be enabled separately, something I am not prepared to do


     


    I cant copy the file in my PHP script to /var/services/mysql/TABLENAME as it is outside or /var/services/web


     


    So short of manually copying the FTP'd file to my table directory, how could I copy it from my PHP script?


     


    This also leads to my second question 'how do I access files outside my web root'


     


    Thanks


  8. I am trying to upload a large dataset in CSV format for batch loading into a MYSQL table using LOAD DATA INFILE

     

    The CSV file (test.csv) is in /var/services/web/php

    My table is in /var/services/mysql/TABLENAME

     

    When I run the SQL command from a PHP script I get an error ERROR: Can't get stat of '/var/services/mysql/TABLENAME/test.csv' (Errcode: 2) Which I believe is because the file needs to be in /var/services/mysql/TABLENAME. Indeed, if I move it there, it works fine

     

    If I try and use the LOCAL switch LOAD DATA LOCAL INFILE I get an error stating that feature is not available. Research shows it can cause a security hole and needs to be enabled separately, something I am not prepared to do

     

    I cant copy the file in my PHP script to /var/services/mysql/TABLENAME as it is outside or /var/services/web

     

    So short of manually copying the FTP'd file to my table directory, how could I copy it from my PHP script?

     

    This also leads to 'how do I access files outside my web root'

     

    Thanks

     

     

     

     

    My scripts is in /var/services/web/php

     

     

     

    , this directory is not accessable from my PHP script. I can FTP the CSV file to the server but I cannot copy the file to my table's directory and I cannot assess the FTP folder from within the LOAD DATA INFILE

  9. Hi

     

    Not sure if anyone can help me here - probably better off asking on a VB forum.

     

    I have a desktop database application written in Visual Basic 6. As records are added to the local VB6 database, copies are POSTed to my PHP application. Users can add records to the PHP application on-line, and these record(s) a transferred down to the desktop system for inclusion into the VB6 database - all works fine (100 way to skin a cat I suppose).

     

    I was wondering, what the best way of polling the server to see if there are any records waiting to be downloaded?

     

    I am currently using an HTTP POST and checking the response

     

    Thanks...

     

     

  10. Hi 

    I have a desktop system which uses plain text files for its storage and  I need to do a one off import of these files (tables) into a SQL table

     

    The largest table as just under 2 million records each of 850 bytes in length

     

    I have written a PHP script and used set_time_limit to zero. The server ran for about 8 hours but did not import the entire table

     

    Maybe I should be uploading a CSV? 

     

    What is the best way to go about this - best practice/suggestions please

     

     

  11. Hi

     

    As my application grows, I am becoming more and more concerned about my configuration and .INC files which are contained within sub directories of my web root folder.

     

    I am lead to understand that it is good practice to move sensitive files (those containing passwords and mysql logon credentials) outside of the general www folder

     

    How do I access those files in PHP with, say an include or required statement

     

    I am currently using include'../configuration/config.php'  how do I access files above ../

     

    Thanks

     

     

  12. Hi

     

    As I get deeper into PHP I am always coming across a situation where I have multiple condition testing. I end up coding thus:

     

    If (condition){

     

         } else {

     

    }

    This can get very messy when you get 4 or 5+ conditions to test for.

     

    In other languages, I have used loops and then use break out of the loop if a condition fails:

     

    WHILE(TRUE)

     

         if (!condition) {

              break;

         }

     

    break;

    }

     

     

    Can anyone comment or make a better suggestion pls

     

    Thanks

     

  13. Hi

     

    I can't get flock() to work, it seems to be such a simple function but I am stumped.

     

    What I think I know...

     

    1. There is a blocking and advisory mode (blocking, waits for a lock whereas advisory lets you know if a lock was succesfully applied)

     

    2. Some UNIX systems do not support blocking

     

    3 Open the file with fopen (+r), apply flock() and if the lock is successful, write to the file.

     

    I have my script 

     
    $bse = fopen($filename, "r+"); //Open for reading and writing; place the file pointer at the beginning of the file. File must exist
        if (!flock($bse, LOCK_EX))
            {
                echo "Waiting for lock on ".$filename;
            }

     

     

    I am using this method to open a file, get a serial number, increment the serial number, write it back to the file then add the serial number to a MySQL table with UNIQUE set on the serial number field. I to this to test if the serial number has been added before and thus test the file locking.

     

    It does not work, I get duplicate serial numbers trying to be added.

     

     

     

    Anyone got any pointers as to what I may be doing wrong

  14. Hi

     

    I have a self calling script which does the following:

     

    Stage 1: First run, it detects that $_POST is empty, and so displays a chunk of html which prompts for a password.

    Stage 2: When resubmitted, it detects $_POST and displays another chunk of html which prompts the user for some values

    Stage 3; When resubmitted the second time, $_POST is detected, along with the user values and some php is executed and a menu displayed.

     

    So, question is this, what is the best method to output the html at stage 1 and stage 2?

    I have tried using echo statements and wrapping each chunk in a function = messy. 

    I have tried using HEREDOCS (<<<VARNAME), better but ties my HTML to my script which is a pain

    I am thinking to use file_get_contents("../html/chunk1.htm") this seems quite elegant and allows me to get someone else on our team to design the HTML keeping it out of my script

     

    Thoughts and suggestions?

     

    Thanks as ever

     

    p.s. who pays for this site, are donation accepted?

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