1

I am a newbie in coding. I am learning php and python.

I want to take data from user. For this I used google and found a form based on html and php

index.html

<html>
<body>

<form action="data.php" method="get">
TEXT1: <input type="text" name="text1">
TEXT2: <input type="text" name="text2">
<input type="submit">
</form>

</body>
</html>

Now data.php can use:

$_GET["text1"] $_GET["text2"]

But my script is in python. I don't know how to use the data given by user.

Please help.

Regards, Abhishek.

4

2 回答 2

1

You could the system(..) [http://php.net/manual/en/function.system.php] command to call your python script with command line arguments.

system('python myScript.py ' . $_GET['text1'] . ' ' . $_GET['text2']);

Although I would really advice against using user provided input in this way, if a user would send 1;rm -rf /;echo as $_GET['text1'] your system would die.. (assuming apache is running as root, which would also be a bad idea)

于 2013-03-30T07:33:30.720 回答
1

If you use a python framework like Pylons/Pyramid, you add your request parameters to your processing function, for instance:

def process_data(request):

   text1 = request.params.get('text1')

于 2013-03-30T07:37:01.127 回答