Jump to content

anupamsaha

Members
  • Posts

    251
  • Joined

  • Last visited

    Never

Everything posted by anupamsaha

  1. Try this. Changes are marked in brown.
  2. There you are!!! Per DML of "properties", while inserting value in properties.Agent_ID, the same Agent_Id MUST EXISTS in agents.Agent_Id. Did you check that?
  3. Little BUG fixed in your code. Use this code snippet and test. <?php /** * Geolocation API access * * @param string $ip IP address to query * @param string $format output format of response * * @return string XML, JSON or CSV string */ function get_ip_location($ip, $format="xml") { /* Set allowed output formats */ $formats_allowed = array("json", "xml", "raw"); /* IP location query url */ $query_url = "http://iplocationtools.com/ip_query.php?ip="; /* Male sure that the format is one of json, xml, raw. Or else default to xml */ if(!in_array($format, $formats_allowed)) { $format = "xml"; } $query_url = $query_url . "{$ip}&output={$format}"; /* Init CURL and its options*/ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $query_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 15); /* Execute CURL and get the response */ //return curl_exec($ch); $response = curl_exec($ch); if ( $format == 'xml' ) { $xmlObj = simplexml_load_string($response); return $xmlObj->CountryCode; } } $location_data = get_ip_location($_SERVER[REMOTE_ADDR]); if ( $location_data == 'US' ) { echo "this is a united states ip";} else { echo "this is not a united states ip";} ?>
  4. Your form element is named as "name" Agent Name:<input type="text" name="name" value="<?php echo $Agent_name; ?>" /> So, change as follows: $Agent_Name = $_POST['name']; And, PHP and any programming language or script does not allow SPACE in a variable name.
  5. Please provide your code here, so that I can help you better.
  6. Its PHP 4 style. Not required in PHP5. In PHP5, call by reference is a default. You can omit the "&" sign.
  7. It will be more easier to compare with the country code rather than country name: if ( $xmlObj->CountryCode == 'US' ) { // DO YOUR STAFF HERE } Will it help?
  8. Please remove the UNIQUE KEY (Agent_Id) from the "properties" table and try.
  9. Try the new extended function as below: <?php /** * Geolocation API access * * @param string $ip IP address to query * @param string $format output format of response * * @return string XML, JSON or CSV string */ function get_ip_location($ip, $format="xml") { /* Set allowed output formats */ $formats_allowed = array("json", "xml", "raw"); /* IP location query url */ $query_url = "http://iplocationtools.com/ip_query.php?ip="; /* Male sure that the format is one of json, xml, raw. Or else default to xml */ if(!in_array($format, $formats_allowed)) { $format = "xml"; } $query_url = $query_url . "{$ip}&output={$format}"; /* Init CURL and its options*/ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $query_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 15); /* Execute CURL and get the response */ $response = curl_exec($ch); /* Get CountryName */ if ( $format == 'xml' ) { $xmlObj = simplexml_load_string($response); return $xmlObj->CountryName; } } $location_data = get_ip_location("70.112.156.140"); echo $location_data; ?>
  10. Hello, I have extended the code a bit in order to get the <CountryName></CountryName> node from xml string. <?php /** * Geolocation API access * * @param string $ip IP address to query * @param string $format output format of response * * @return string XML, JSON or CSV string */ function get_ip_location($ip, $format="xml") { /* Set allowed output formats */ $formats_allowed = array("json", "xml", "raw"); /* IP location query url */ $query_url = "http://iplocationtools.com/ip_query.php?ip="; /* Male sure that the format is one of json, xml, raw. Or else default to xml */ if(!in_array($format, $formats_allowed)) { $format = "xml"; } $query_url = $query_url . "{$ip}&output={$format}"; /* Init CURL and its options*/ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $query_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 15); /* Execute CURL and get the response */ $response = curl_exec($ch); if ( $format == 'xml' ) { $xmlObj = simplexml_load_string($response); return $xmlObj->CountryName; } } $location_data = get_ip_location("70.112.156.140"); //here you could use a regular expression or something along those lines to extract the information that is between "<CountryName>" and "</CountryName>" (I'll let you figure that one out on your own or see if someone else here can do it for you. //from there just use your previous code to check and see if the country name matches your if statements ?> Hope this will help.
  11. From the error message, it seems that the SQL failure is due to foreign key constraints. Can you please paste the SQL for creating the "agents" table here? Thanks
  12. Do you want to hide DB access info from others? If yes, simply put the config file outside the web root directory and include the file from there in all the required script. Also, you can set the path of the config file include path directive in php.ini file, if possible or in .htaccess file. Hope this will help.
  13. Try this: $sql = "INSERT INTO `users` (`firstname`, `lastname`, `email`, `username`, `password`)"; I think there is a conflict between the field password and MySQL function PASSWORD. So, its better to enclose all the MySQL table name and field names with backquote (`) character in order to avoid the conflict. Hope this will help.
  14. Please remove the single quote character from $variable. //$variable = "Trois-Rivières"; $variable2 = htmlentities($variable); Hope this will help.
  15. Try this: If you have "empty" filled in the field: echo (empty($yourDataField) ? '' : $yourDataField); If you have "NULL" filled in the field: echo (is_null($yourDataField) ? '' : $yourDataField); Cheers! Hope this will help.
  16. Yes, check with full path. If it si not working, do the following: 1. Check if XYZ has the execution permission. 2. Check the owner of the command XYZ in your Linux system. Also, check the user running PHP (usually apache or www). If you see that the owner of XYZ is not the PHP user, change the owner to PHP user. Hope, this will help.
  17. Can you provide some more information here that what are you trying to do and if any error you are encountering?
  18. Both will work provided the variable $location has some valid path in it. include/require will fail if it sees include "/link.php" . Both of them cannot refer to a relative path. Hope this will help.
  19. Do a MX record validation. Please refer to "getmxrr" function. http://www.php.net/getmxrr
  20. Hello, Session hijacking is a common thing in place. To overcome this, you can regenerate a new session id every time by using session_regenerate_id(). This function will replace the current session id with a new one, and keep the current session information. For your help, I can also provide you the background functionality of session_start(). The events that take place when session_start() is issued in PHP script. 1. PHP determines whether session garbage-collection must take place: a. PHP divides the value of the runtime configuration setting "session.gc_probability" by the value of the runtime configuration setting "session.gc_divisor". (The default value for session.gc_probability is 1. The default value for session.gc_divisor is 100.) b. PHP generates a random number. c. If the random number is smaller than the calculated quotient (i.e. result of session.gc_probability / session.gc_divisor), garbage-collection activates 2. If garbage collection is to take place, PHP checks all files in the directory specified by the runtime configuration setting "session.save_path". It is looking for all files older than the number of seconds in the runtime configuration setting "session.gc_maxlifetime". All files older than that number of seconds are deleted. 3. PHP then checks to see whether a cookie named the same as the runtime configuration setting "session.name" was sent by the browser. a. If the cookie exists, PHP fetches the value of that cookie. That value is the current session id. b. If the cookie does not exist, PHP generates a session id and sets a cookie named as specified in "session.name". The value of that cookie is the generated session id. 4. If a session cookie with a session id was sent by the user's browser, PHP will look in the directory specified by "session.save_path". It is looking for a file named "sess_" plus the session id. a. If that file is found, PHP reads the session data stored there and populates $_SESSION. b. If the file is not found, PHP initializes $_SESSION as empty Hope this information will help you. Cheers!
×
×
  • 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.