Jump to content

converting asp to php cant figure out the problem?


undertainment

Recommended Posts

I get error in the php script on lines 55, 76, and 81.  I highlighted the errors in php code.  I cant figure out what i should use.  I attached the pages incase someone wants to play around with the code alittle.  My server runs apache, php 5.2.10, on a windows machine.  Code is for a simple dns server for users to signup for secondary dns service.

 

 

Asp Script

<%

  Option Explicit

  Dim sdnsIPAddr, sdnsPort, sdnsPassword, UserListFile

 

  sdnsIPAddr="127.0.0.1"

  sdnsPort=8053

  sdnsPassword=""

  UserListFile="user.txt"

 

  ProcessRequest

 

  Sub ProcessRequest()

    Dim userID, password, hostName, ipAddr

    userID=Request.QueryString("user")

    password=Request.QueryString("pw")

    hostName=LookupUsersHostName(userID,password)

    If hostName="" Then

      Response.Write "Error: Invalid UserID or Password!"

      Exit Sub

    End If

    ipAddr=Request.QueryString("ip")

    If not ipAddr>"" Then ipAddr=Request.ServerVariables("REMOTE_HOST")

    If UpdateSimpleDNS(hostName, ipAddr) Then

      Response.Write "OK"

    Else

      Response.Write "ERROR: Could not update DNS server"

    End If

  End Sub

 

  Function LookupUsersHostName(userID, password)

    Dim FSO, CfgFile, x, a

    Set FSO=Server.CreateObject("Scripting.FileSystemObject")

    Set CfgFile=FSO.OpenTextFile(server.MapPath(UserListFile))

    LookupUsersHostName=""

    While Not CfgFile.AtEndOfStream And LookupUsersHostName=""

      x=CfgFile.ReadLine()

      a=Split(x,";",3)

      If a(0)=userID and a(1)=password Then LookupUsersHostName=a(2)

    Wend

    CfgFile.Close

  End Function

 

  Function UpdateSimpleDNS(hostName, ipAddr)

    dim url, httpObj

    url = "http://" & sdnsIPAddr & ":" & sdnsPort & "/updatehost?" & _

          "host=" & hostName & "&data=" & ipAddr

    Set httpObj=Server.CreateObject("Microsoft.XMLHTTP")

    If sdnsPassword>"" Then

      httpObj.open "GET", url, False, "admin", sdnsPassword

    Else

      httpObj.open "GET", url, False

    End If

    httpObj.send

    UpdateSimpleDNS=(httpObj.Status=200)

  End Function

 

%>

 

PHP Script converted

<?

// Option $Explicit;

 

$sdnsIPAddr="127.0.0.1";

$sdnsPort=8053;

$sdnsPassword="";

$UserListFile="user.txt";

 

ProcessRequest();

 

function ProcessRequest()

{

  extract($GLOBALS);

 

  $userID=$_GET["user"];

  $password=$_GET["pw"];

  $hostName=LookupUsersHostName($userID,$password);

  if ($hostName=="")

  {

 

    print "Error: Invalid UserID or Password!";

    return $function_ret;

 

  }

 

  $ipAddr=$_GET["ip"];

  if (!$ipAddr>"")

  {

    $ipAddr=$_SERVER["REMOTE_HOST"];

  }

  if (UpdateSimpleDNS($hostName,$ipAddr))

  {

 

    print "OK";

  }

    else

  {

 

    print "ERROR: Could not update DNS server";

  }

 

  return $function_ret;

}

 

function LookupUsersHostName($userID,$password)

{

  extract($GLOBALS);

 

  // $FSO is of type "Scripting.FileSystemObject"

  $CfgFile=fopen($DOCUMENT_ROOT.$UserListFile,"r");

  $function_ret="";

  while(!feof($CfgFile) && $LookupUsersHostName=="")

  {

 

    $x=fgets($CfgFile)();

    $a=explode(";",$x);

    if ($a[0]==$userID && $a[1]==$password)

    {

      $function_ret=$a[2];

    }

  }

  fclose($CfgFile);

  return $function_ret;

}

 

function UpdateSimpleDNS($hostName,$ipAddr)

{

  extract($GLOBALS);

 

  $url="http://".$sdnsIPAddr.":".$sdnsPort."/updatehost?".

    "host=".$hostName."&data=".$ipAddr;

  // $httpObj is of type "Microsoft.XMLHTTP"

  if ($sdnsPassword>"")

  {

 

  $httpObj->open"GET"    $url    $False    $sdnsPassword;

  }

    else

  {

 

    $httpObj->open"GET"    $url    $False;

  }

 

  $httpObj->send;

  $function_ret=($httpObj->Status=200);

  return $function_ret;

}

 

?>

 

[attachment deleted by admin]

I'm not looking at whether or not any of your code will work, but just on the basis of the errors:

 

$x=fgets($CfgFile)();

 

function(arguments) format.  The extra () is invalid.

 

$x=fgets($CfgFile);

 

The UpdateSimpleDNS is going to need a rewrite.  I'd suggest, based on what you're doing there, that you use curl

Archived

This topic is now archived and is closed to further replies.

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