سؤال

Okay These types of questions are normally very broad, however I will try my best to explain exactly what I want to try and achieve.

What I want is to allow users to enter some information (This will be an IP Address) using a HTML input form, and then once they click submit the data they entered would be added to the PHP code where they can then see the results. Here's the PHP code (Only a snippet of some of the code.)

$SERVER_IP="//IP OF USER INPUT WOULD GO HERE"; 

I understand that this could possibly be more of a task than simply just adding a HTML input form a few lines of code, if this is the case, could you please point me to where I can get information on how to do these sort of things?

Thanks you.

هل كانت مفيدة؟

المحلول

If it doesn't need to be permanent, use a form, then access the variable by $_GET['var'] or $_POST['var']. You can even save it to the user's $_SESSION. If it needs to be permanent, use a database..don't have a user edit your PHP

You can also use something like jQuery to append data to a div container, example:

HTML:

<input id="input_form_id" type="text"/>
<button id="add_ip">Add</button>
<div id="ip_addresses"></div>

Jquery:

$("#add_ip").click(function() {
    var ip = $("#input_form_id").val();
    $("#ip_addresses").append(ip + "<br/>");
});

Jsfiddle: http://jsfiddle.net/hvBwK/

نصائح أخرى

Allowing users to edit a PHP file would open up all kinds of security problems that you don't want.

Instead, that code should be $SERVER_IP="//fetch the user input from a file or DB"; and the UI part should handle putting that user input there - as data, not PHP code.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top