PHP - Different Types Of Returns Using Gethostbyaddr() And Remote_addr
can someone explain to me why PHP returns so many different variants when throwing out visitor info using this piece of code? $ip = gethostbyaddr($_SERVER['REMOTE_ADDR']); here are some examples I have seen recently: planetlab24.gino-research.net.in.tum.de 10.32.64.124 49.129.197.35.bc.googleusercontent.com abts-north-dynamic-142.110.68.182.airtelbroadband.in 173-20-152-84.client.mchsi.com now, obviously i can understand the google one, and a few others. but, given the info and insight on these pages: https://www.php.net/manual/en/function.gethostbyaddr.php , and https://www.php.net/reserved.variables.server , why are the returns so different for different people? why does PHP see all different kinds of things? is the cause the way the user’s server is configured? some identifying info OF the server? and what about reserved IPs? like the “10.xx…” one I listed above? I’ve seen hundreds from that pool, and other blocks of reserved ones, and they have never had alpha-chars included in their captures. it’s always only the IP numbers. there a reason for that? really, all I’m looking for is why I see what I see. anyone help? furthermore, does anyone know if other server-side languages like c#, python, ruby or any js frameworks return different results than PHP ever would? thanks. Similar TutorialsHi guys. This is my first question on phpFreaks (the other 900+ posts I've made were always an attempt to help someone else) Here's the issue: when using gethostbyaddr($_SERVER['REMOTE_ADDR']) on a local machine (current using MAMP on OS X) the name returned is not the first entry in my /etc/hosts file. (On php.net there's another person also commenting on this and saying that apparently gethostbyaddr() selects a random entry from the file.) This is not really an issue, since everything will work fine on my FreeBSD production server where each IP address has only one DNS record (I'm building the company's intranet, so I know exactly what's in our DNS tables) but I'm curious to know if anyone has had the same issue/problem and if there's a way around it. (Logic/Common sense tells me the first record should be the one returned) Currently I have the following information in my /etc/hosts file: Code: [Select] 127.0.0.1 localhost 127.0.0.1 iSy 255.255.255.255 broadcasthost ::1 localhost fe80::1%lo0 localhost # Other names for testing purposes 127.0.0.1 name1.blablabla.com 127.0.0.1 name2.blablabla.com 127.0.0.1 name3.blablabla.com 127.0.0.1 name4.blablabla.com 127.0.0.1 name5.blablabla.com 127.0.0.1 name6.blablabla.com 127.0.0.1 name7.blablabla.com 127.0.0.1 name8.blablabla.com the value returned is always line 8: name2.blablabla.com. If I comment out that line, then it moves 'randomly' to line 12: name6.blablabla.com and sticks with it even if I shut down the servers and then boot up again. any ideas? cheers. I log the hostname of the computers when they do certain things in our Intranet. When the hostname is logged, certain clients are getting both the hostname and the localhost IP address added. For example, if the PC name is TOMS-PC, the hostname logged is TOMS-PC172.0.0.1 Other clients are logging just the hostname as it should be. All I use to grab the hostname is: Code: [Select] $hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']); Any clues as to what causes this? At the very bottom of the page i am using the tag <? $_SERVER['REMOTE_ADDR'] ?> to show the clients ip address but it is not working any ideas where i am going wrong? Code: [Select] <?php require("../include/validate_mem_cookie.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Edit Your Pictures</title> </head> <link rel="stylesheet" type="text/css" href="../graphic_include/newstudio.css"> <body> <?php $uincookie = $_COOKIE["uin"]; require("../include/mysqldb.php"); $con = mysql_connect("$dbhost","$dbuser","$dbpass"); $imgff = "/p1c5_u91o4d/" ; if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("$dbame", $con); $result = mysql_query("SELECT * FROM Reg_Profile_images WHERE uin ='$uincookie'"); $i=1; while($rows = mysql_fetch_array($result)){ $image_zero = $rows[image_zero] ; $image_one = $rows[image_one] ; $image_two = $rows[image_two] ; $image_three = $rows[image_three] ; $image_four = $rows[image_four] ; $image_five = $rows[image_five] ; $image_six = $rows[image_six] ; $image_seven = $rows[image_seven] ; $image_eight = $rows[image_eight] ; $image_nine = $rows[image_nine] ; $image_ten = $rows[image_ten] ; $image_eleven = $rows[image_eleven] ; if (!empty($rows[image_zero])) { print "<p> </p> <table width=\"0\" border=\"0\"> <tr> <td><table width=\"112\" height=\"129\" border=\"0\"> <tr> <td><img src=\"$imgff$image_zero\" alt=\"\" width=\"156\" height=\"166\" /></td> </tr> <tr> <td><form id=\"form3\" name=\"form1\" method=\"post\" action=\"..\p1c5_u91o4d\delete_image.php\"> <label> <div align=\"left\"> <input type=\"submit\" name=\"button3\" id=\"button3\" value=\"Delete Picture\" /> <input type=\"hidden\" name=\"img[]\" value=\"$image_one\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_two\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_three\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_four\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_five\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_six\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_seven\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eight\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_nine\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_ten\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eleven\"> <input type=\"hidden\" name=\"remove\" value=\"$image_zero\"> <input type=\"hidden\" name=\"updel\" value=\"image_zero\"> </div> </label> </form></td> </tr> <tr> <td><form id=\"form4\" name=\"form2\" method=\"post\" action=\"change_order.php\"> <label> <div align=\"left\"> <input type=\"submit\" name=\"button3\" disabled=\"disabled\" id=\"button4\" value=\"PRIMARY PICTURE\" /> <input type=\"hidden\" name=\"img[]\" value=\"$image_zero\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_one\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_two\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_three\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_four\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_five\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_six\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_seven\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eight\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_nine\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_ten\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eleven\"> </div> </label> </form></td> </tr> </table></td>\n"; } if (!empty($rows[image_one])) { print "<td><table width=\"112\" height=\"129\" border=\"0\"> <tr> <td><img src=\"$imgff$image_one\" alt=\"\" width=\"156\" height=\"166\" /></td> </tr> <tr> <td><form id=\"form5\" name=\"form1\" method=\"post\" action=\"..\p1c5_u91o4d\delete_image.php\"> <label> <div align=\"left\"> <input type=\"submit\" name=\"button4\" id=\"button5\" value=\"Delete Picture\" /> <input type=\"hidden\" name=\"img[]\" value=\"$image_zero\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_two\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_three\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_four\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_five\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_six\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_seven\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eight\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_nine\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_ten\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eleven\"> <input type=\"hidden\" name=\"remove\" value=\"$image_one\"> <input type=\"hidden\" name=\"updel\" value=\"image_one\"> </div> </label> </form></td> </tr> <tr> <td><form id=\"form6\" name=\"form2\" method=\"post\" action=\"change_order.php\"> <label> <div align=\"left\"> <input type=\"submit\" name=\"button4\" id=\"button6\" value=\"Make Primary\" /> <input type=\"hidden\" name=\"img[]\" value=\"$image_one\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_zero\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_two\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_three\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_four\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_five\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_six\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_seven\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eight\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_nine\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_ten\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eleven\"> </div> </label> </form></td> </tr> </table></td>\n"; } if (!empty($rows[image_two])) { print "<td><table width=\"112\" height=\"129\" border=\"0\"> <tr> <td><img src=\"$imgff$image_two\" alt=\"\" width=\"156\" height=\"166\" /></td> </tr> <tr> <td><form id=\"form7\" name=\"form1\" method=\"post\" action=\"..\p1c5_u91o4d\delete_image.php\"> <label> <div align=\"left\"> <input type=\"submit\" name=\"button5\" id=\"button7\" value=\"Delete Picture\" /> <input type=\"hidden\" name=\"img[]\" value=\"$image_zero\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_one\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_three\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_four\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_five\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_six\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_seven\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eight\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_nine\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_ten\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eleven\"> <input type=\"hidden\" name=\"remove\" value=\"$image_two\"> <input type=\"hidden\" name=\"updel\" value=\"image_two\"> </div> </label> </form></td> </tr> <tr> <td><form id=\"form8\" name=\"form2\" method=\"post\" action=\"change_order.php\"> <label> <div align=\"left\"> <input type=\"submit\" name=\"button5\" id=\"button8\" value=\"Make Primary\" /> <input type=\"hidden\" name=\"img[]\" value=\"$image_two\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_zero\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_one\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_three\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_four\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_five\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_six\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_seven\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eight\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_nine\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_ten\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eleven\"> </div> </label> </form></td> </tr> </table>\n"; } if (!empty($rows[image_three])) { print " </td> <td><table width=\"112\" height=\"129\" border=\"0\"> <tr> <td><img src=\"$imgff$image_three\" alt=\"\" width=\"156\" height=\"166\" /></td> </tr> <tr> <td><form id=\"form9\" name=\"form1\" method=\"post\" action=\"..\p1c5_u91o4d\delete_image.php\"> <label> <div align=\"left\"> <input type=\"submit\" name=\"button6\" id=\"button9\" value=\"Delete Picture\" /> <input type=\"hidden\" name=\"img[]\" value=\"$image_zero\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_one\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_two\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_four\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_five\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_six\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_seven\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eight\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_nine\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_ten\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eleven\"> <input type=\"hidden\" name=\"remove\" value=\"$image_three\"> <input type=\"hidden\" name=\"updel\" value=\"image_three\"> </div> </label> </form></td> </tr> <tr> <td><form id=\"form10\" name=\"form2\" method=\"post\" action=\"change_order.php\"> <label> <div align=\"left\"> <input type=\"submit\" name=\"button6\" id=\"button10\" value=\"Make Primary\" /> <input type=\"hidden\" name=\"img[]\" value=\"$image_three\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_zero\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_one\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_two\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_four\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_five\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_six\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_seven\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eight\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_nine\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_ten\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eleven\"> </div> </label> </form></td> </tr> </table>\n"; } if (!empty($rows[image_four])) { print " </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr> </table> <p> </p> <table width=\"0\" border=\"0\"> <tr> <td><table width=\"112\" height=\"129\" border=\"0\"> <tr> <td><img src=\"$imgff$image_four\" alt=\"\" width=\"156\" height=\"166\" /></td> </tr> <tr> <td><form id=\"form\" name=\"form1\" method=\"post\" action=\"..\p1c5_u91o4d\delete_image.php\"> <label> <div align=\"left\"> <input type=\"submit\" name=\"button\" id=\"button\" value=\"Delete Picture\" /> <input type=\"hidden\" name=\"img[]\" value=\"$image_zero\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_one\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_two\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_three\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_five\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_six\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_seven\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eight\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_nine\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_ten\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eleven\"> <input type=\"hidden\" name=\"remove\" value=\"$image_four\"> <input type=\"hidden\" name=\"updel\" value=\"image_four\"> </div> </label> </form></td> </tr> <tr> <td><form id=\"form2\" name=\"form2\" method=\"post\" action=\"change_order.php\"> <label> <div align=\"left\"> <input type=\"submit\" name=\"button\" id=\"button2\" value=\"Make Primary\" /> <input type=\"hidden\" name=\"img[]\" value=\"$image_four\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_zero\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_one\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_two\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_three\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_five\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_six\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_seven\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eight\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_nine\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_ten\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eleven\"> </div> </label> </form></td>\n"; } if (!empty($rows[image_five])) { print " </tr> </table></td> <td><table width=\"112\" height=\"129\" border=\"0\"> <tr> <td><img src=\"$imgff$image_five\" alt=\"\" width=\"156\" height=\"166\" /></td> </tr> <tr> <td><form id=\"form11\" name=\"form1\" method=\"post\" action=\"..\p1c5_u91o4d\delete_image.php\"> <label> <div align=\"left\"> <input type=\"submit\" name=\"button\" id=\"button11\" value=\"Delete Picture\" /> <input type=\"hidden\" name=\"img[]\" value=\"$image_zero\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_one\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_two\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_three\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_four\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_six\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_seven\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eight\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_nine\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_ten\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eleven\"> <input type=\"hidden\" name=\"remove\" value=\"$image_five\"> <input type=\"hidden\" name=\"updel\" value=\"image_five\"> </div> </label> </form></td> </tr> <tr> <td><form id=\"form12\" name=\"form2\" method=\"post\" action=\"change_order.php\"> <label> <div align=\"left\"> <input type=\"submit\" name=\"button\" id=\"button12\" value=\"Make Primary\" /> <input type=\"hidden\" name=\"img[]\" value=\"$image_five\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_zero\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_one\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_two\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_four\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_three\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_six\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_seven\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eight\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_nine\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_ten\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eleven\"> </div> </label> </form></td> </tr> </table></td>\n"; } if (!empty($rows[image_six])) { print " <td><table width=\"112\" height=\"129\" border=\"0\"> <tr> <td><img src=\"$imgff$image_six\" alt=\"\" width=\"156\" height=\"166\" /></td> </tr> <tr> <td><form id=\"form13\" name=\"form1\" method=\"post\" action=\"..\p1c5_u91o4d\delete_image.php\"> <label> <div align=\"left\"> <input type=\"submit\" name=\"button\" id=\"button13\" value=\"Delete Picture\" /> <input type=\"hidden\" name=\"img[]\" value=\"$image_zero\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_one\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_two\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_three\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_four\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_five\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_seven\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eight\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_nine\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_ten\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eleven\"> <input type=\"hidden\" name=\"remove\" value=\"$image_six\"> <input type=\"hidden\" name=\"updel\" value=\"image_six\"> </div> </label> </form></td> </tr> <tr> <td><form id=\"form14\" name=\"form2\" method=\"post\" action=\"change_order.php\"> <label> <div align=\"left\"> <input type=\"submit\" name=\"button\" id=\"button14\" value=\"Make Primary\" /> <input type=\"hidden\" name=\"img[]\" value=\"$image_six\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_zero\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_one\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_two\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_four\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_five\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_three\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_seven\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eight\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_nine\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_ten\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eleven\"> </div> </label> </form></td> </tr> </table></td> \n"; } if (!empty($rows[image_seven])) { print " <td><table width=\"112\" height=\"129\" border=\"0\"> <tr> <td><img src=\"$imgff$image_seven\" alt=\"\" width=\"156\" height=\"166\" /></td> </tr> <tr> <td><form id=\"form15\" name=\"form1\" method=\"post\" action=\"..\p1c5_u91o4d\delete_image.php\"> <label> <div align=\"left\"> <input type=\"submit\" name=\"button\" id=\"button15\" value=\"Delete Picture\" /> <input type=\"hidden\" name=\"img[]\" value=\"$image_zero\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_one\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_two\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_three\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_four\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_five\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_six\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eight\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_nine\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_ten\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eleven\"> <input type=\"hidden\" name=\"remove\" value=\"$image_seven\"> <input type=\"hidden\" name=\"updel\" value=\"image_seven\"> </div> </label> </form></td> </tr> <tr> <td><form id=\"form16\" name=\"form2\" method=\"post\" action=\"change_order.php\"> <label> <div align=\"left\"> <input type=\"submit\" name=\"button\" id=\"button16\" value=\"Make Primary\" /> <input type=\"hidden\" name=\"img[]\" value=\"$image_seven\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_zero\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_one\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_two\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_four\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_five\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_six\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_three\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eight\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_nine\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_ten\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eleven\"> </div> </label> </form></td> </tr> </table></td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr>\n"; } if (!empty($rows[image_eight])) { print " <td> </td> <td> </td> <td> </td> <td> </td> </tr> </table> <p> </p> <table width=\"0\" border=\"0\"> <tr> <td><table width=\"112\" height=\"129\" border=\"0\"> <tr> <td><img src=\"$imgff$image_eight\" alt=\"\" width=\"156\" height=\"166\" /></td> </tr> <tr> <td><form id=\"form17\" name=\"form1\" method=\"post\" action=\"..\p1c5_u91o4d\delete_image.php\"> <label> <div align=\"left\"> <input type=\"submit\" name=\"button2\" id=\"button17\" value=\"Delete Picture\" /> <input type=\"hidden\" name=\"img[]\" value=\"$image_zero\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_one\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_two\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_three\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_four\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_five\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_six\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_seven\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_nine\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_ten\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eleven\"> <input type=\"hidden\" name=\"remove\" value=\"$image_eight\"> <input type=\"hidden\" name=\"updel\" value=\"image_eight\"> </div> </label> </form></td> </tr> <tr> <td><form id=\"form18\" name=\"form2\" method=\"post\" action=\"change_order.php\"> <label> <div align=\"left\"> <input type=\"submit\" name=\"button2\" id=\"button18\" value=\"Make Primary\" /> <input type=\"hidden\" name=\"img[]\" value=\"$image_eight\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_zero\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_one\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_two\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_four\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_five\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_six\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_seven\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_three\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_nine\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_ten\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eleven\"> </div> </label> </form></td>\n"; } if (!empty($rows[image_nine])) { print "</tr> </table></td> <td><table width=\"112\" height=\"129\" border=\"0\"> <tr> <td><img src=\"$imgff$image_nine\" alt=\"\" width=\"156\" height=\"166\" /></td> </tr> <tr> <td><form id=\"form19\" name=\"form1\" method=\"post\" action=\"..\p1c5_u91o4d\delete_image.php\"> <label> <div align=\"left\"> <input type=\"submit\" name=\"button2\" id=\"button19\" value=\"Delete Picture\" /> <input type=\"hidden\" name=\"img[]\" value=\"$image_zero\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_one\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_two\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_three\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_four\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_five\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_six\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_seven\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eight\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_ten\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_eleven\"> <input type=\"hidden\" name=\"remove\" value=\"$image_nine\"> <input type=\"hidden\" name=\"updel\" value=\"image_nine\"> </div> </label> </form></td> </tr> <tr> <td><form id=\"form20\" name=\"form2\" method=\"post\" action=\"change_order.php\"> <label> <div align=\"left\"> <input type=\"submit\" name=\"button2\" id=\"button20\" value=\"Make Primary\" /> <input type=\"hidden\" name=\"img[]\" value=\"$image_nine\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_zero\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_one\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_two\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_four\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_five\"> <input type=\"hidden\" name=\"img[]\" value=\"$image_six\"> & I have been recording IP address's on a website since June 2006. This has worked for years up until 9th Dec 2014 when my database has stopped reporting the IP address and all I get since is 127.0.0.1
What has happened? I don't own the server it is being hosted by stramline.net
HELP
Hello, I have a website where only a couple of people can access it, so the number of IPs logged in is very limited. Everything submitted by the 'admins' logged in is sent to a specific folder dependent of their IP Address. Again they can't access the website through a proxy or anything because there's a limited range of IPs that is allowed. Can I trust $_SERVER['REMOTE_ADDR'] to give a valid IP so the log-system would be 100 % stable and efficient ? I am trying to make sure I don't get an "Undefined Index" error. Will this code work... $ip = (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''); Debbie Hi, I have just started creating my first class in php. I'm trying to assign $_SERVER['REMOTE_ADDR']; to a protected variable but I keep getting an error message. I'm still trying to get my head around oop php. My current code is "protected $user_ip = $_SERVER['REMOTE_ADDR'];" and the error message is "Parse error: syntax error, unexpected T_VARIABLE". What types of data can the $_SESSION cookie store? Objects? Resources? And how are these stored in text form? I have a scenario where users are downloading files from a legacy system and uploading the files into a new system that I am supporting. Many of the files do not have an extension (most are tiffs).
The issue we have is that the new system doesn't know how to open these files (we have them open in a preview window in the new system). I have tried numerous solutions, including finfo_file() and the depreciated mime_content_type() funcitons), but all they seem to return is "application/octet-stream".
Thanks.
Is it possible to define a variable's type at the start of your code? I believe you can "cast" a variable, but can I do something like this... Code: [Select] name string; age integer; gender string; children array; single: boolean; I know some people say PHP is better suited for the web because it is loosely-typed, but I'm anal-retentive and like my structure!! TomTees This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=353735.0 I am getting this error: Fatal error: Unsupported operand types. Code: [Select] <?php $new_player_credits = $player_credits + $game_credits; $new_player_exp = $player_exp + $game_exp; ?> I have absolutely no clue why I'm getting the error. Both of my variables are integers. Hi all, I'm new to PHP and just looking for any advice anyone might have on the following problem I'm having. I have created a database and tables for registering and logging in users. Each record has three different User Types (or roles): 1, 2 and 3. Once the session has started, I would like to make certain menu items available to certain User Types. I suppose it is some sort of if...elseif statement such as: <?php if($UserType==1) echo {"<p>Menu1</p>"} elseif($UserType==2) echo {"<p>Menu2</p>"} elseif($UserType==3) echo {"<p>Menu3</p>"}; ?> Would anybody be able to point me in the right direction? I'd really appreciate any help at all. I've asked this question before but still haven't really figured out how best to implement it, and have found myself hitting another roadblock. I have multiple types of charts (i.e. bar, pie, etc), and various endpoints to access them. I like to keep my routing script uncluttered, and feel the following does so. $app->get('/chart', function (Request $request, Response $response) { //List of chart with optional filtering $this->chartService->index($request->getQueryParams()); return $this->chartResponder->index($response, $index); }); $app->post('/chart', function (Request $request, Response $response) { //Create a new chart of type (i.e. bar, pie, etc) specified by type parameter $chart=$this->chartService->create($request->getParsedBody()); return $this->chartResponder->create($response, $chart); }); $app->get('/chart/{id:[0-9]+}', function (Request $request, Response $response, $args) { //View chart of given ID $chart=$this->chartService->detail((int)$args['id']); return $this->chartResponder->delete($response, $chart); }); $app->delete('/chart/{id:[0-9]+}', function (Request $request, Response $response, $args) { //Delete chart of given ID $this->chartService->delete((int)$args['id']); return $this->chartResponder->delete($response, null); }); $app->post('/chart/{id:[0-9]+}/series', function (Request $request, Response $response, $args) { //Add a new series to the collection for chart with given ID $chart=$this->chartService->addSeries((int)$args['id'], $request->getParsedBody()); return $this->chartResponder->update($response, $chart); }); $app->put('/chart/{id:[0-9]+}/series/{seriesPosition:[0-9]+}', function (Request $request, Response $response, $args) { //Modify series of given position in the collection for chart with given ID $chart=$this->chartService->updateSeries((int)$args['id'], (int)$args['seriesPosition'], $request->getParsedBody()); return $this->chartResponder->update($response, $chart); }); //More endpoints for chart of given ID... I then created the following service to support the endpoints. Off topic, but is this a service or a controller? My index() method is chart type agnostic. My create() method needs a means to determine what type of chart to create, and does so using the received chart "type" passed in the body to get the applicable repository. All the other methods receive the chart ID in the URL path and use it to first get the chart entity and then get the applicable repository based on the object. All seems good! <?php namespace NotionCommotion\ChartBuilder\Service; use NotionCommotion\ChartBuilder\Entity\Chart; class ChartService { protected $em; public function __construct(\Doctrine\ORM\EntityManager $em) { $this->em = $em; } public function index(array $params=[]):array { return $this->em->getRepository(Chart::class)->index($params); } public function create(array $params):Chart { //Get the specific repo based on $params['type]. Not perfect, but good enough $discriminatorMap=$this->em->getClassMetadata(Chart::class)->discriminatorMap; $repo = $this->em->getRepository($discriminatorMap[$params['type']]); //Validate data $chart=$repo->create($params); $this->em->persist($chart); $this->em->flush(); return $chart; } public function read(int $id):Chart { return $this->em->getRepository(Chart::class)->find($id); } public function delete(int $id):void { $this->em->remove($this->read($id)); $this->em->flush(); } public function addSeries(int $idPublic, array $id):Chart { $chart=$this->read($id); //Validate data $repo=$this->em->getRepository(get_class($chart)); $repo->addSeries($chart, $params); $this->em->persist($chart); $this->em->flush(); return $chart; } public function updateSeries(int $id, int $position, array $params):Chart { $chart=$this->read($id); $series=$chart->getSeries(); $seriesNode=$series->offsetGet($position); //Validate data $repo=$this->em->getRepository(get_class($seriesNode)); $repo->update($seriesNode, $params); $this->em->persist($chart); $this->em->flush(); return $chart; } } Until... I find myself needing to put non-database related functionality in the repository and violating the single responsibility principle. I am not a complete purist and might be willing to do so, however, there does not appear to be a clean way to inject dependencies in a Doctrine repository. One thought I had was to create specialized services maybe as follows: $c['chartService'] = function ($c) { return new ChartService( $c[EntityManager::class], [ 'bar'=>function ($c) {return new BarChartService($c[EntityManager::class]);}, 'pie'=>function ($c) {return new PieChartService($c[EntityManager::class], $c['someOtherObject']);}, //add more types... ] ); };
class ChartService { protected $em, $subServices=[]; public function __construct(\Doctrine\ORM\EntityManager $em, $subServices) { $this->em = $em; $this->subServices = $subServices; } public function index(array $params=[]):array {/* no change */} public function create(array $params):Chart {/* maybe no change */} public function __call($name, $args) { $chart=$this->em->getRepository(Chart::class)->find($args[0]); $subservice=$this->getSubservice($chart); $args[0]=$chart; return $subservice->$name(...$args); } } abstract class AbstractSpecificChartService { protected $em; public function __construct(\Doctrine\ORM\EntityManager $em) { $this->em = $em; } public function __call($name, $args) { throw new \Exception("Method $name not supported"); } protected function getSubservice(Chart $chart):self { //Haven't figured out but can do so if needed. } public function delete(Chart $chart):void { //Include methods common to all charts here $this->em->remove($chart); $this->em->flush(); } protected function helperMethods($foo) { //If necessary. } } class BarChartService extends AbstractSpecificChartService { //Override __construct if necessary public function updateSeries(Chart $chart, int $position, array $params):Chart { //Note that Chart and not $id is passed. //implement code as needed return $chart; } }
So, after this long story, how should I implement this? Thank you friends my url is like this Category=Love&ID=1 now in url if i do something like this Category4637=Hate19203&ID=1 the details are still showing, how can i fix this? if someone type Capegory instead of Category and a wrong category name which do not exist with that id in db send them to index.php? I'm working on a two-file upload form and want to be able to check the mime types of two filenames in a string variable.
The code below was working when the variable @resume_path contained just one filename. How can I modify this to accommodate two files?
when I echo $resume_path, I get, for example: cover_letter_centerline.doc, cover_letter_ctg.doc
Thanks!
//DO NOT TRUST $_FILES['upfile']['mime'] VALUE !! //Check MIME Type by yourself. $finfo = new finfo(FILEINFO_MIME_TYPE); if (false === $ext = array_search( $finfo->file($_FILES['resume_path']['tmp_name']), array( 'txt' => 'text/plain', 'doc' => 'application/msword', 'pdf' => 'application/pdf', ), true )) { throw new RuntimeException('Invalid file format.'); } echo "Sorry, invalid file format. Please try again."; echo $ext; Hey Guys, How are custom Mime Types achieved? Had a quick search through the forums, and most of the posts relate to mail() questions. Did a google search and found a completely useless article that told me to edit a non-existent text box. Quick example, the file type I want is .WAgame, I got this far before I realised what I was doing didn't make sense. So I looked up mime types, knowing that this file would not exist. if ($_FILES["file"]["type"] != "file/WAgame") { naughty! } Help! Edit: I searched the forums and the Internet as a whole looking for more information on this, but all I've turned up is a lot of information on /how/ to use create_function(), not /when/ to use it. For instance: http://en.wikipedia.org/wiki/Lambda_calculus Let me reiterate that I understand how it works in general. However, in several years of PHP programming, even through the development of fairly complex, robust systems, I can only think of one case where I recall creating a dynamic function and even here I feel like it was a design mistake. Of course, I use anonymous functions all the time in JavaScript for callback code. It seems to be used from time-to-time to iterate over and apply transformations to sets, but I don't understand the advantage over foreach() for such a task. So, if someone is so-inclined, would you mind listing a general scenario or two where create_function() is the correct and appropriate solution to the problem? I am in the process of creating a script where only certains video types can be uploaded but at the moment am stuck.
Here is my code -
<?php $title = isset($_POST['title']) ? $_POST['title'] : null; $desc = nl2br(isset($_POST['description'])) ? $_POST['description'] : null; $name = isset($_POST['fullname']) ? $_POST['fullname'] : null; $email = isset($_POST['email']) ? $_POST['email'] : null; $country = isset($_POST['country']) ? $_POST['country'] : null; $video = isset($_FILES['video']); $videoname = isset($_FILES['video']['name']); $videotmp = isset($_FILES['video']['tmp_name']); $videosize = isset($_FILES['video']['size']); $videotype = isset($_FILES['video']['type']); $videoacceptable = array( "video/mp4", "video/ogg", "video/quicktime", ); $videopath = "/videos/"; $videofile = $videopath . $video; if(isset($_POST['submit'])) { //ERROR MESSAGES / VALIDATION if(empty($title)) { $errors[] = "A title is required"; echo "<style type=\"text/css\"> #title { background-color:#F5A9A9;border:1px solid #DF0101; } </style>"; } elseif(strlen($title) > 80) { $errors[] = "Your title can only be 80 characters long"; echo "<style type=\"text/css\"> #title { background-color:#F5A9A9;border:1px solid #DF0101; } </style>"; } if(empty($desc)) { $errors[] = "A description is required"; echo "<style type=\"text/css\"> #description { background-color:#F5A9A9;border:1px solid #DF0101; } </style>"; } if(empty($name)) { $errors[] = "Please enter your full name"; echo "<style type=\"text/css\"> #fullname { background-color:#F5A9A9;border:1px solid #DF0101; } </style>"; } elseif(strlen($name) > 32) { $errors[] = "Your name can only be 32 characters long"; echo "<style type=\"text/css\"> #fullname { background-color:#F5A9A9;border:1px solid #DF0101; } </style>"; } if(empty($email)) { $errors[] = "Please enter your email address"; echo "<style type=\"text/css\"> #email { background-color:#F5A9A9;border:1px solid #DF0101; } </style>"; } elseif(strlen($email) > 50) { $errors[] = "Your email addess can only be 50 characters long"; echo "<style type=\"text/css\"> #email { background-color:#F5A9A9;border:1px solid #DF0101; } </style>"; } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $errors[] = "Please enter a valid email address"; echo "<style type=\"text/css\"> #email { background-color:#F5A9A9;border:1px solid #DF0101; } </style>"; } if($videosize = 0) { $errors[] = "You forgot to upload a video"; } elseif($videosize >= 20000000) { $errors[] = "Your video size is too large, 20mb max"; } elseif(!in_array($videotype, $videoacceptable)) { $errors[] = "The file type is not allowed, only allowed .mp4, .ogg and .mov"; } if(count($errors) === 0) { $connect = mysqli_connect("localhost","username","password"); if(!$connect) { header("Location:"); // ADD ERROR LINK } $dbselect = mysqli_select_db("database"); if(!$dbselect) { header("Location:"); // ADD ERROR LINK } $query = mysqli_query("INSERT INTO cover_videos(title, desc, name, email, country, videotmp, videotype, videosize, videopath) VALUES('$title','$desc','$name','$email','$country','$videotmp','$videotype','$videosize','$videopath')"); move_uploaded_file($videotmp, $videofile); //SEND AN EMAIL TO THE USER $to = $email; $subject = "Thank's for your upload"; $message = ' <html> <head><title>We have received your video</title></head> <body> <h3>Good News!</h3> <p>We have recieved your video and is awaiting approval.</p> </body> </html> '; $headers = 'FROM: no-replyk' . "\r\n"; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers = 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); header("Location:"); //SUCCESSFUL UPLOAD PAGE } } ?>So whats happening is when i go to upload a file, im uploading a .mov file but the error message that pops up is "The file type is not allowed, only allowed .mp4, .ogg and .mov" but the .mov mime is in the videoacceptable array so im a bit stuck at the moment, any know whats the problem? |