Jump to content

heeha

Members
  • Posts

    43
  • Joined

  • Last visited

Posts posted by heeha

  1. It is better if you code it as you will learn more from doing it yourself than copy and pasting someone elses code. 

     

    I have simplified the pseudo code

    <?php
    
    if (isset $_GET['url'])  // check url exists - documentation http://php.net/isset
    {
         if(filter_input $_GET['url'] filter PHP_URL_HOST) // check url is valid - documentation http://php.net/filter_input using PHP_URL_HOST as the filter
         {
              $hostname = parse_url $_GET['url'] component PHP_URL_HOST; // get hostname and assign to variable - documentation http://php.net/parse_url
              $dns_records = dns_get_record $hostname type DNS_A; // use dns_get_record for hostname - documentation http://php.net/dns_get_record
         }
         else
         {
              echo url is not valid // echo an error message, url is not valid
         }
    }
    
    ?>
    
    your html form here
    <form ...>...</form>
    
    <?php
    
    
    if (isset $dns_records) // documentation http://php.net/isset
    {
        //output dns records here
        foreach($dns_records as $record)
        {
            // output dns $record here
        }
    }

    I have provided 90% of the code for you. If you read the documentation I have referenced in the code you should be able to fill in the missing pieces with ease.

    if (isset $dns_records) // why we we have to check isset or not here as well, don't we just call the output? We already know the url exists by checking isset($_POST['url'])) and have already know the dns is working we just didnt output it above.
    {
        //output dns records here
        foreach($dns_records as $record)
        {
            // output dns $record here
        }
    }
    
    
    

    2. When I enter google.com, ( as its a hostname) not a url and form only takes url as we have told php to take url only not the hostname to process via form. 

    how do i make sure that when a user enter google.com, or www.google.com in the form it will still process the information and brings the dns record. 

     

    Above all, i m successfully able to output every records. Well some are missing such as reverse ip. 

    Well, i also now would learn to add those information to database just to make sure my coding experience keeps on growing and would learn further more. Thanks to you for helping all that out. 

    
    <?php
    $siteErr="";
    $site="";
    
    
    if ($_SERVER["REQUEST_METHOD"] == "GET") {
       $site = trim_useless($_GET['url']);
      
    }
     if (empty($_GET['url'])) {
         $site = "";
       } else {
         $site = trim_useless($_GET['url']);
         if (!preg_match("/\b(??:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$site)) {
           $siteErr = "Invalid URL"; 
         }
       }
    
    function trim_useless($data) {
       $data = trim($data);
       $data = stripslashes($data);
       $data = htmlspecialchars($data);
       return $data;
    }
    ?>
    
    

    why this above code wasnt working, I know i wasn't able to tell the php to not to process the form. 

  2. Completely Agreed, I had faced the same issue. Fortunately when i was about to leave to the sign-up page, i accidentally got accepted. I would definitely say, that they need to look for the security code bug issue if there is any. I typed security code for over 15 types to join. It was totally a bad experience. 

  3.  In which part am i going wrong? 

    Am I going ok? 
    
    <?php
    
    $url= $_POST['url'];
    
    if(isset($url))  //did to check if url is there or not.
    {
    
    if(filter_input($url, PHP_URL_HOST)) //did to check if your is valid or not 
    
    {
    
    
    $host= parse_url($url, PHP_URL_HOST);
    print "the host is $host";  //did to output the hostname
    foreach($host as $hostname); // assigned $host as $hostname
    
    
    $dnsinfo= dns_get_record($hostname, DNS_A);
    print_r($dnsinfo); // to check if records are getting printed or not. 
    }
    }
    
    
    ?>
    
    <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="Post">
    Enter URL : <input type="text" name="url">
    
    Submit: <input type="submit" name="submit">
    </form>
    
  4. How can we answer that question when we have absolutely no idea what, if anything, you are putting the "myname" field?

     

    And what is in $url?

    How does it get there?

    sorry, I messed the code : 

     

    <?php 

    $url = $_GET['myname']; 

     

    $host = parse($url, PHP_URL_HOST); 

     

    print "The host is" .$host['host']. ".";

     

    ?>

     

    let say, if i put google.com in the form and then process it. shouldn't it output the hostname?

  5. Well, I m still having troubles, as I read those pages, and those to me appears to technical terms I wasn't able to understand much. I would have them if they were much simplfied way. Surely I am not looking that you full fill those missing pieces, and I m  interested in filling them myself so I guess I can keep the rest those code for sometime and in the time being i would love to clarify other things. 

     

    LEt say a part of that code: 

     

    <form action="<?php echo $_SERVER["PHP_SELF"];?>">

    name : <input name=myname"  type="text">

    <input type="submit">

    </form>

     

    <?php 

    $host= $_GET['myname']; 

     

    $host = parse($url, PHP_URL_HOST); 

     

    print "The host is" .$host['host']. ".";

     

    ?>

     

    or 

    <?php 

    $host= $_GET['myname'];

    $host= parse_url($host);

     

    print "the host is " .$host['host']. ".";

     

    ?>

    Why doesnt this code output the host such as google.com or anyother. 

  6. Well, I dont copy paste, what I do i surely change them to my needs and see if that works on my server or not. But those coding given at w3schools are easy to get answers with but doing coding myself is very tough as of now. 

  7. I tried my best being a complete new to programming but i m unable to get the working properly. 

    <!DOCTYPE html>
    <html>
    <head>
    <style>
    table , tr, td, th {
    border: 3px solid pink; 
    background-color: yellow; 
    border-collapse: collapse;
    }
    
    </style>
    </head>
    
    <body>
     <?php
     $site= $_GET['url'];
     if(!filter_var($site, FILTER_VALIDATE_URL) === false) {
     }else {
     $site="";
     }
     
    if ($_GET['url'] exists)
    {
    
    if($_GET['url'])
         {
              $site= parse_url($_GET['url'], PHP_URL_HOST);
    		  
    		  foreach($site as $host){
    		  $result= dns_get_record([$host], DNS_A);
    		  }
              
         }
         else
         {
              $siteErr= "url is not valid";
         }
    }
    
    ?>
    
     
    
    <form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" method="GET">
    Enter URL : <input type="text" name="url">
    <span class="error"> * <?php echo $siteErr;?></span>
    Submit: <input type="submit" name="submit">
    </form>
    <div>
    
    <?php
    
    if ($result)
    {
        print_r($result);
    }
    
    ?>
    </body>
    </html>
  8. I take lessons and tutorial from w3schools for learning purpose and when I read it there and tries to add those on my server, it seems so easy but when I try to code things myself, its so much hard to code. 

     

     

  9.  

    It is processing the form regardless because you have not instructed PHP not to do that. PHP only does what you explicitly instruct it to do.

     

    You should only retrieve/show the dns records for the url if a) a url has been submitted and b) the url passes your validation.

     

    But your next problem is dns_get_record() does not take a url. It requires only a hostname (the domain). If you want to get the hostname from a url you will first want to call parse_url and grab the hostname segment, using  PHP_URL_HOST  flag. Also if you want to validate a url use filter_input using  FILTER_VALIDATE_URL  as the filter

     

    Pseudo code for how to layout your code

    <?php
    
    if ($_GET['url'] exists)
    {
         if(url is valid)
         {
              get hostname from url
              get dns record for hostname and save to a variable
         }
         else
         {
              output error, url is not valid
         }
    }
    
    ?>
    
    show form
    
    <?php
    
    if (have dns records)
    {
        output dns records here
    }
    
    ?>
    

    Thanks for the help but I m completely new to the programming, I filled the above based upon tutorials taken from w3schools. So the Pseudo code layout you just placed, i m unable to enter information correctly. I would be happy if you could put the code in there so i can understand based upon my above novice coding. I tried filling those places but I m unable to get anything and I m sure I am adding all of them wrong. 

  10. I am trying to code to but having some troubles. 

    
    <?php
    $siteErr="";
    $site="";
    
    
    if ($_SERVER["REQUEST_METHOD"] == "GET") {
       $site = trim_useless($_GET['url']);
      
    }
     if (empty($_GET['url'])) {
         $site = "";
       } else {
         $site = trim_useless($_GET['url']);
         if (!preg_match("/\b(??:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$site)) {
           $siteErr = "Invalid URL"; 
         }
       }
    
    function trim_useless($data) {
       $data = trim($data);
       $data = stripslashes($data);
       $data = htmlspecialchars($data);
       return $data;
    }
    ?>
    
    <form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" method="GET">
    Enter URL : <input type="text" name="url">
    <span class="error"> * <?php echo $siteErr;?></span>
    Submit: <input type="submit" name="submit">
    </form>
    <div> 
    <?php 
    $site= dns_get_record($_GET['url'], DNS_MX);
    foreach ($site as $in){
    echo "<table>";
    echo "<tr>";
    echo "<th>Host</th>";
    echo "<th>Class</th>";
    echo "</tr>";
    echo "<tr>";
    echo "<td>" .$in['host']. "</td>";
    echo "<td>" .$in['class']. "</td>";
    echo "</table>";
    }
    ?>

     

    1.

    Warning: dns_get_record(): An unexpected server failure occurred. in /home/u992092914/public_html/b/test.php on line 48

    Warning: Invalid argument supplied for foreach() in /home/u992092914/public_html/b/test.php on line 49

     

     

    2. Form validation doesnt work. I mean even if i enter abc rather than some .com , it will still process the form.

     

    3. No invalid Url gets displayed if display, doesnt stop form to get processed.

     

  11. I was trying to get dns_AAAA for ipv6 but i do not get the any result, I only get ouput as "array() " in the page. 

    $a = dns_get_record("example.com", DNS_AAAA);
    print_r($a); 
    
    doesnt output the ipv6, it only gets the "array()";
    
    
    
  12. Update : Solved. It automatically parses each information and shows all the dns correctly. 

    Works only with the following code, and rest of the code told by many other didn't get any oputput at all. DNS_ALL does work but it has problem in output due as too much complication in handling multidimensional arrays. Foreach loop is also needed. 
    
    $site = dns_get_record( "example.com", DNS_A);
    echo $site['host'] . ' ip address is ' . $site['ip'] . '<br />';
    
  13. Update, finally solved. I guess i saw it somewhere something wrong. It works 

     

    lets say there are 4 name server for a site and 2 for another. 

     

    how do i display using if or elseif statement that if only website has two NS it will only display 2 and if a site has 4 server it display 4only. As i m using table to display the data, I place 4 table rows so when a website has for ns it works fine but when other website has 2 NS, the remaining two (table data) doesnt work properly. 

     

    Thanks. 

  14.  

    It is showing that line 5 times because  dns_get_record( "example.com", DNS_ALL);  returns a multidimensional array of each type of dns record for that domain.

     

    In your case $site is a multidimensional array, which contains 5 sub-arrays. In each of these sub-arrays there is a "host" key. Your foreach loop is looping through each of these sub-arrays and outputting the "host" key. This is why line "the name of the host is example.com" is outputted five times. If you only want to host to be outputted once,  you need add logic to your foreach loop example

    $putput_host = false;
    foreach( $site as $anyvariable)
    {
        // check if the host has been outputted
        if(!$output_host)
        {
            echo "the name of the host is" .$anyvariable['host']. "." ;
            echo "<br>";
            // set $output_host to true, we have outputted the host
            $putput_host = true;
        }
    }

    If you are doing is outputting the host, then have dns_get_record return only one dns record, such as DNA_A

    $site = dns_get_record( "example.com", DNS_A);
    echo $site['host'] . ' ip address is ' . $site['ip'] . '<br />';

    Code 1.  Doesnt work. I have tried. 

     

    regarding code 2. It does work but the problem i face now is that 

    $site = dns_get_record( "example.com", DNS_NS);
    print_r($site);
    //outputs : Array ( [0] => Array ( [host] => example.com [class] => IN [ttl] => 5 [type] => NS [target] => my-servers.net ) [1] => Array ( [host] => example.com [class] => IN [ttl] => 5 [type] => NS [target] => your-servers.net ) [1] => Array ( [host] => example.com [class] => IN [ttl] => 5 [type] => NS [target] => this-servers.net ) )
    
    
    foreach($site as $anyvariable) {
    
    echo $site['host'] . ' ip address is ' . $site['ip'] . '<br />';
    echo $site['host'] . ' ip address is ' . $site['ip'] . '<br />';
    
     //outputs the first value "ok" but doesnt out the rest of the name servers different ans output the value same for both. 
    
    How do i output in way that each gets displayed with all the values for ns1 and ns2 and so on? Each target value is different. 
    

    @ginerjm : tried code as is, doesnt output anything. 

  15.  

    It is showing that line 5 times because  dns_get_record( "example.com", DNS_ALL);  returns a multidimensional array of each type of dns record for that domain.

     

    In your case $site is a multidimensional array, which contains 5 sub-arrays. In each of these sub-arrays there is a "host" key. Your foreach loop is looping through each of these sub-arrays and outputting the "host" key. This is why line "the name of the host is example.com" is outputted five times. If you only want to host to be outputted once,  you need add logic to your foreach loop example

    $putput_host = false;
    foreach( $site as $anyvariable)
    {
        // check if the host has been outputted
        if(!$output_host)
        {
            echo "the name of the host is" .$anyvariable['host']. "." ;
            echo "<br>";
            // set $output_host to true, we have outputted the host
            $putput_host = true;
        }
    }

    If you are doing is outputting the host, then have dns_get_record return only one dns record, such as DNA_A

    $site = dns_get_record( "example.com", DNS_A);
    echo $site['host'] . ' ip address is ' . $site['ip'] . '<br />';

     

    Thanks, I get it completely but I guess foreach loop is still needed to output the variable. 

     

    $site= dns_get_record( "example.com", DNS_A); 

    echo $site['host'] . 'ip address is ' .$site['ip']. '<br />'; 

     

    doesnt output any values but adding foreach loops does as it's still inside the array. 

     

    $site= dns_get_record( "example.com", DNS_A); 

     

    foreach( $site as $anyvariable) {

    echo $anyvariable['host'] . 'ip address is ' .$anyvariable['ip']. '<br />';

    }

     

    Tried several times after trying foreach loop, helped me get the values. 

  16. Thanks, I get it a little bit. 

     

    But the problem now I face is that, there are 5 array, there it shows the same out as 5 fives instead of showing just once. 

     

    foreach( $site as $anyvariable) {

    echo "the name of the host is" .$anyvariable['host']. "." ;

    echo "<br>";

    }

     

    and the output comes out as 

     

    the name of the host is example.com 

    the name of the host is example.com 

    upto 5 times. 

     

    How do i restricted it the the limit to 1 or the  output the "echo" only the number of times i want to output it. 

  17. Hey, I am new to programming including html or any kind. 

     

    I was trying to get dns info via php 

     

    Lets say we have a website example.com, and we output the info for it as 

     

    $site= (dns_get_record( "example.com", DNS_ALL); 

     

    print_r( $site); 

     

    which output as 

    Array ( [0] => Array ( [host] => example.com [class] => IN [ttl] => 3500 [type] => A [ip] => xxx.xxx.xx.xxx ) [1] => Array ( [host] => example.com [class] => IN [ttl] => 172002 [type] => NS [target] => ns1.example.com ) [2] => Array ( [host] => example.com [class] => IN [ttl] => 17002 [type] => NS [target] => ns2.example.com ) and so on )

     

    but I dont want this info to be output like this.

     

    I want it to appear as 

     

    echo :The name of host is" . $anyvariable['host']. "."; 

     

    and which output it as 

     

    The name of host is example.com.  and same for the others values. or appear something like this on webpage not in array forms. 

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