python to php

Solutions on MaxInterview for python to php by the best coders in the world

showing results for - "python to php"
Noelie
03 Jul 2017
1Depending on what you are doing, system() or popen() may be perfect. Use system() if the Python script has no output, or if you want the Python script's output to go directly to the browser. Use popen() if you want to write data to the Python script's standard input, or read data from the Python script's standard output in php. popen() will only let you read or write, but not both. If you want both, check out proc_open(), but with two way communication between programs you need to be careful to avoid deadlocks, where each program is waiting for the other to do something.
2
3If you want to pass user supplied data to the Python script, then the big thing to be careful about is command injection. If you aren't careful, your user could send you data like "; evilcommand ;" and make your program execute arbitrary commands against your will.
4
5escapeshellarg() and escapeshellcmd() can help with this, but personally I like to remove everything that isn't a known good character, using something like
6
7preg_replace('/[^a-zA-Z0-9]/', '', $str)
Davide
06 Jun 2017
1import requests
2import json
3data = {
4   "api_key": "PRIVATE_API_KEY",
5   "profiles": [
6       {
7           "$consent": ["sms"],
8           "phone_number": "+12345678900",
9           "sms_consent": True
10       }
11   ]
12}
13headers = {
14   "Content-Type": "application/json",
15   "Cache-Control": "no-cache"
16   }
17conv = json.dumps(data)
18response = requests.request("POST", "https://a.klaviyo.com/api/v2/list/{LIST_ID}/subscribe", data=conv, headers=headers)
19print(response.text)
Emna
17 Feb 2018
1<?php echo "Hello" ?>
Maria
01 Jan 2021
1import requests
2import json
3data = {
4   "api_key": "PRIVATE_API_KEY",
5   "profiles": [
6       {
7           "$consent": ["sms"],
8           "phone_number": "+12345678900",
9           "sms_consent": True
10       }
11   ]
12}
13headers = {
14   "Content-Type": "application/json",
15   "Cache-Control": "no-cache"
16   }
17conv = json.dumps(data)
18response = requests.request("POST", "https://a.klaviyo.com/api/v2/list/{LIST_ID}/subscribe", data=conv, headers=headers)
19print(response.text)