Good Day Everyone,

I really need help on PHP because I do not have enough knowledge on this programming language.

I need to convert my vb.net code - controller/handler - into PHP. The problem is, is this even possible? Does PHP has variable that is equal to httpcontext of .net? I have been searching this on the net since last Thursday but I can\'t get any idea.

I really appreciate any help.. Thank you in advance..

Here is my code in vb.net that need to be converted to PHP

------------------------------
using System;
using System.Text;
using System.Web;
using System.IO;
using System.Net;
using System.Configuration;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Collections.Specialized;
using System.Web.Script.Serialization;

namespace Accenture.Collab.SearchApp.Handlers
{
/// <summary>
/// Summary description for searchwidget
/// </summary>
public class SearchHandler : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{
ProxyCall(context);

//context.Response.ContentType = \"application/json; charset=utf-8\";
//string name = \"Ian\";
//JavaScriptSerializer serializer = new JavaScriptSerializer();
//context.Response.Write(serializer.Serialize(name));
}

private void ProxyCall(HttpContext context)
{
//dynamic path = new uri

NameValueCollection section = (NameValueCollection)ConfigurationManager.GetSection(\"SearchServiceSettings\");

string queryString = context.Request[\"p\"];
if (queryString == \"\")
{
string enterpriseid = HttpContext.Current.User.Identity.Name.ToString();
string pipeDelimitedProperties = \"sps-jobtitle|countryhome|workforcegroup\";
//string eidQueryString = \"Enterpriseid\";
string user = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
string eid = user.Replace(\"DIR\\\\\", \"\");
// { \"Enterpriseid\": eid, \"PipeDelimitedProperties\": pipeProp }
string userName = section[\"userName\"];
string password = section[\"userPassword\"];
string domain = section[\"domain\"];
Uri baseUri = new Uri(section[\"peoplewebserviceUrl\"]);
string serviceFolder = section[\"peoplewebserviceFolder\"];

//dynamic path = new Uri(baseUri, serviceFolder + \"api/searchwidget\");
dynamic path = new Uri(baseUri, serviceFolder).ToString();
//dynamic pString = context.Request[\"p\"].Replace(\"|a|\", \"&\");

//string chard = encode\"{ \\\";

string param = \"{\" + \" \" + \'\\\"\' + \"EnterpriseId\" + \'\\\"\' + \":\" + \'\\\"\' + eid + \'\\\"\' + \",\" + \'\\\"\' + \"PipeDelimitedProperties\" + \'\\\"\' + \":\" + \'\\\"\' + pipeDelimitedProperties + \'\\\"\' + \"}\";


context.Response.Write(HTTPClient.PostRequestJSONResponse(path, param));
}
else
{
string userName = section[\"userName\"];
string password = section[\"userPassword\"];
string domain = section[\"domain\"];
Uri baseUri = new Uri(section[\"serviceUrl\"]);
string serviceFolder = section[\"serviceFolder\"];

//dynamic path = new Uri(baseUri, serviceFolder + \"api/searchwidget\");
//string path = baseUri.ToString() + serviceFolder;
//dynamic pString = context.Request[\"p\"].Replace(\"|a|\", \"&\");

//string box = \"{\\\"EnterpriseId\\\":\\\"ian.m.s.estrada\\\",\\\"PipeDelimitedProperties\\\":\\\"firstname|lastname\\\"}\";

//WebRequest request = WebRequest.Create(path.ToString());
//context.Response.Write(HTTPClient.PostRequestJSONResponse(path, box));

dynamic path = new Uri(baseUri, serviceFolder);
dynamic pString = context.Request[\"p\"].Replace(\"|s|\", \"&\");
pString = pString.Replace(\"|a|\", \"&\");

context.Response.Write(HTTPClient.GetRequestJSONResponse(path + pString));
}
}

public bool IsReusable
{
get
{
return false;
}
}
}
}

--------

using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Configuration;

namespace Accenture.Collab.SearchApp
{
public class HTTPClient
{
public static JObject PostRequestJSONResponse(string url, string parameters)
{
string retVal = SubmitRequest(\"POST\", url, parameters);
return !string.IsNullOrWhiteSpace(retVal) ? JObject.Parse(retVal) : new JObject();
}

public static JObject GetRequestJSONResponse(string url)
{
string retVal = SubmitRequest(\"GET\", url, string.Empty);
return !string.IsNullOrWhiteSpace(retVal) ? JObject.Parse(retVal) : new JObject();
}

public static JObject PutRequestJSONResponse(string url, string parameters)
{
string retVal = SubmitRequest(\"PUT\", url, parameters);
return !string.IsNullOrWhiteSpace(retVal) ? JObject.Parse(retVal) : new JObject();
}

public static void DeleteRequest(string url, string parameters)
{
string retVal = SubmitRequest(\"DELETE\", url, parameters);
}

public static string SubmitRequest(string type, string url, string parameters)
{
string retVal = string.Empty;
HttpWebRequest myWebRequest = null;
Stream dataStream = null;
StreamReader reader = null;
WebResponse response = null;

string ElasticSearchUserName = ConfigurationManager.AppSettings[\"userName\"];
string ElasticSearchPassword = ConfigurationManager.AppSettings[\"userPassword\"];
string ElasticSearchDomain = ConfigurationManager.AppSettings[\"domain\"];

try
{
// Here we create the request and write the POST data to it.
myWebRequest = (HttpWebRequest)WebRequest.Create(url);
myWebRequest.Timeout = Timeout.Infinite;
myWebRequest.Method = type;
myWebRequest.ContentType = \"application/json\";
//myWebRequest.Credentials = new NetworkCredential(ElasticSearchUserName, ElasticSearchPassword, ElasticSearchDomain);
myWebRequest.Credentials = new NetworkCredential(\"acn.ppl.admin\", \"yK!bR5kB(dW%sY\", \"DIR\");

if (type != \"GET\")
{
using (var writer = new StreamWriter(myWebRequest.GetRequestStream()))
{
writer.Write(parameters);
}
}

// Get the response.
response = myWebRequest.GetResponse();

dataStream = response.GetResponseStream();

// Open the stream using a StreamReader for easy access.
reader = new StreamReader(dataStream);

// Read the content.
retVal = reader.ReadToEnd();
}
finally
{
// Clean up the streams and the response.
myWebRequest = null;

if (dataStream != null)
dataStream.Close();

if (reader != null)
reader.Close();

if (response != null)
response.Close();
}

return retVal;
}
}
}