Jump to content

ginerjm

Members
  • Posts

    6,906
  • Joined

  • Last visited

  • Days Won

    99

Posts posted by ginerjm

  1. Somewhat rudimentary but seems like it should do what you want to do - if I understand your question. What do you see as the problem?

     

    ps - stop using the MySQL_* functions. Simply read the manual and notice all the warnings about them. Really.

    Also - where is $used defined? Is error checking turned on so you will catch errors while developing this?

  2. 1 - Four posts at once? Really?

     

    2 - You showed us a bunch of code.

     

    3 - You mentioned that you just found out about the existence(?) of Sessions in PHP.

     

    4 - You didn't ask a question.

    EDIT - My bad. After posting I re-read the topic heading and see that there is a (sorta) question there. So - use my reference to the manual to learn about sessions.

    As for how one writes a secure login script there is lots of info out there and samples too. Everyone does their logins differently so do some research and pick the one that makes sense to you and then read up on the functions/features it uses to learn from it and then ask for tips once you have written something.

     

    A good point of reference as a newcomer to PHP would be the official PHP manual. Go to 'php.net'. Plenty of knowledge there for you to read up on.

     

     

    PS - It is good practice to separate your html & JS code from your php code - for logical sense and readability and maintenance purposes.

  3. And with Cronix's tip making sense out of these posts, your code needs to reference the cid element like this:

     

    foreach ($items as $item)

    {

    $a = $item['cid'];

    ...

    ...

    }

    Your array is not an object nor does it contain objects, so no 'object notation' is necessary. It is simply an array reference.

     

    PS:

    Are you really constrained into using an array to store your data instead of a much more sensible and practical db table?

  4. Uh.... How is your $items array related at all to the second snippet of code you posted that reads a file into $file? And what do you expect to be read and stored from that snippet? You are simply reading a php file as a 'text' file and storing it as a string(s) in $file. $file will not be an array - it will be a string. Am I missing something?

  5. When you say "new to coding PHP" that means it is time to sit down with a good book or online tutorial and start learning. You'll never learn to code if you don't do it. Nobody here is going to write code for you. But - the people here are very happy to help you correct your attempts.

     

    Have fun and good luck!

  6. This code:

    $stmt->bind_param('issssssib', $escola, $form, $data, $horas,$local,$dest, $datas, $visto, $file_path );
    if (!$stmt->execute())
    {
    echo json_encode(array('status' => 'error', 'message' => 'Opppss...A formação não foi gravada'));
    }
    }
    else
    {
    echo json_encode(array('status' => 'error', 'message' => 'Opppss...A formação não foi gravada'));
    }
    $stmt->close();
    

     

    is flawed and is probably causing your script to not execute. You think that the file is being saved but I suggest that it was already there.

     

    Try adding some echo statements to verify what is happening - after you fix the flaw above.

  7. Who changed the permissions? If what you say is completely accurate, the error message is spot on. You don't have permission to access that file or folder. Did someone remove a user from that folder? Did someone change the user that php is running under? Did your folder name change for some other reason and your access is now flawed?

  8. IMHO you are getting confused by your attempts to use session for something it is not appropriate for.

     

    A session is just that. It is a period of time when there is usage of a browser to connect to your site. It lasts only as long as that activity continues. It can disappear via a timeout if there is no activity on the browser (I believe) but it will continue to live and exist as long as there IS activity on that browser. That's a session. It has no life after the browser is closed so concern about getting rid of certain values is misplaced I believe. (I'm sure if I have made a misstatement here it will be brought to our attention!).

     

    As for your desire to retain some information BETWEEN sessions you need to focus on cookies. Cookies are actually there to help you retain something that you want to last longer than a session. You can create the cookie with an expiration date so that it will eventually go away from lack of use and you can re-set the expiration date every time it is accessed. Sounds like something that already does what you are trying to do.

     

    Now the connection that is missing is how will the cookie relate to the data that you want to 'remember' between sessions? Well if it is simply a username (and id?) then one cookie s/b sufficient. Your script begins, looks for a specific cookie and uses the value of the cookie as the username. If they successfully complete the 'login' and prove that they are eligible to use this app then you can re-write that cookie with an updated expire date.

     

    Your last statement above said you 'need is for username and id to be unset'. Why do you need both in the first place? If you give the user his username and he supplies the password - YOU can then verify the signon and get the id from the db. No need for it to be stored anywhere else between sessions. But if you do need the id saved for some reason, a cookie will work. As for removing them at the close of the browser - I'm confused since your whole effort seems to be how to retain them between sessions and now you're concerned with removing them at the end of the session. Well - a simple session var already does that if you use the normal default settings for sessions.

     

    Hopefully I am not mis-informing you. This is my experience with sessions, which I've never played with and worried about timeout and retentions, etc. If you want something retained between sessions, use a cookie. For stuff during a single session, use session vars. For removing something in a cookie, delete it when you want to un-remember the info. Seems like this should do everything you want.

  9. You don't mention Ajax in your post. Since php is doing the update on the server, it is difficult to have your client produce a pop-up window as a direct result of an insert. The only way to have a pop-up is to do this via an Ajax connection and then you can setup a popup notification or a simple js/jq alert box. The main point is that you must be using Ajax (via JS or JQ)

     

    Of course if you don't want to use ajax, then your script will simply call the server via POST and do the update and return a response page to the client and there you can show whatever message you want whether it is on a popup, an alert box, or a simple box/div on your main page, which is what it appears you are currently doing.

     

    The main point is you can't do a popup directly from php. You have to utilize js/jq to get that, either using ajax or as part of the page load in the ensuing page load.

  10. Barand has provided some great code that normally would be perfect for you Proba. But as you said originally the input can be in 'random order' so this code will not work. Are you sure the input is in "random order"? Seems strange to have a process that produces random input like you describe.

  11. Actually you are using fgetcsv to READ the incoming data.

     

    As I said in my other response to you, the incoming data must be in a recognizable order or you can not do this. Whether the data has identifiers within it or there is a row of headers at the start, either way. But to be completely random is not possible.

     

    I have to wonder how this data was prepared for you with no thought given as to how it would be used.

  12. Is this an HTML problem with the links? Or is it the php that is receiving the page and trying to re-direct the page?

     

    If the former, try an html forum perhaps.

    If the latter, do you have php error checking on? Have you echoed out any info from your script that might help debug the problem? Can you post the RELEVANT code (in proper forum tags) that attempts to handle your input from the html?

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