PHP - Moved: Ip Logging By Country
This topic has been moved to Miscellaneous.
http://www.phpfreaks.com/forums/index.php?topic=353007.0 Similar TutorialsI am trying to invert some arrays, making the x-values y, and the y-values x. I have found the code that works, but I cannot understand for the life of me, I have a multidimensional $data array; that looks like this: Code: [Select] row:0 :: Country:Algeria row:1 :: Country:USA row:2 :: Country:Morocco The following code successfully extracts the appropriate 'column' from my array. Code: [Select] foreach($data as $value){ $invert['country'][] = $value['country']; } It returns: Code: [Select] $invert['country'] = Algeria, USA, Morocco But this makes no sense, it seems more logical that the code should be: Code: [Select] foreach($data as $value){ $invert[] ['country']= $value['country']; } Since we are accepting all values of the first array, and then specifying the second array. What am I missing here? Why is it working backwards? This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=345840.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=359083.0 I have this code, its working pretty fine until i insert "echo "$ipDetail['country']";" to get the converted ip to name its origin Code: [Select] <?php $ip=$_SERVER['REMOTE_ADDR']; function countryCityFromIP($ipAddr) { //function to find country and city from IP address //Developed by Roshan Bhattarai http://roshanbh.com.np //verify the IP address for the ip2long($ipAddr)== -1 || ip2long($ipAddr) === false ? trigger_error("Invalid IP", E_USER_ERROR) : ""; $ipDetail=array(); //initialize a blank array //get the XML result from hostip.info $xml = file_get_contents("http://api.hostip.info/?ip=".$ipAddr); //get the city name inside the node <gml:name> and </gml:name> preg_match("@<Hostip>(\s)*<gml:name>(.*?)</gml:name>@si",$xml,$match); //assing the city name to the array $ipDetail['city']=$match[2]; //get the country name inside the node <countryName> and </countryName> preg_match("@<countryName>(.*?)</countryName>@si",$xml,$matches); //assign the country name to the $ipDetail array $ipDetail['country']=$matches[1]; //get the country name inside the node <countryName> and </countryName> preg_match("@<countryAbbrev>(.*?)</countryAbbrev>@si",$xml,$cc_match); $ipDetail['country_code']=$cc_match[1]; //assing the country code to array //return the array containing city, country and country code return $ipDetail; }$ipDetail="countryCityFromIP('12.215.42.19')"; echo "<b>IP Address= $ip</b> "; echo "$ipDetail['country']"; ?> this is the error Code: [Select] Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/GGME/public_html/addons/iptest.php on line 25 I have the product catalog/shopping cart. I need to modify the registration so that it allows the customer to complete the form but then takes him to a message telling him who to contact based on the country he enters during registration. Maybe an if country=A go to... If country=B go to... else go to... This script should detect what contry a visitor is from via there IP and display there contrys flag. However it does not work, please could you take a look and let me know if there are any obviouse errors as im stumped. Code: [Select] <?php $IPaddress=$_SERVER['REMOTE_ADDR']; $two_letter_country_code=iptocountry($IPaddress); Print "$IPaddress" include("IP_FILES/countries.php"); $three_letter_country_code=$countries[ $two_letter_country_code][0]; $country_name=$countries[$two_letter_country_code][1]; print "Two letters code: $two_letter_country_code<br>"; print "Three letters code: $three_letter_country_code<br>"; print "Country name: $country_name<br>"; // To display flag $file_to_check="flags/$two_letter_country_code.gif"; if (file_exists($file_to_check)){ print "<img src=flags/$file_to_check width=30 height=15><br>"; }else{ print "<img src=flags/noflag.gif width=30 height=15><br>"; } function iptocountry($ip) { $numbers = preg_split( "/\./", $ip); include("ip_files/".$numbers[0].".php"); $code=($numbers[0] * 16777216) + ($numbers[1] * 65536) + ($numbers[2] * 256) + ($numbers[3]); foreach($ranges as $key => $value){ if($key<=$code){ if($ranges[$key][0]>=$code){$two_letter_country_code=$ranges[$key][1];break;} } } if ($two_letter_country_code==""){$two_letter_country_code="unkown";} return $two_letter_country_code; } ?> Thanks in Advance, Monk3h. Hi all Got a problem that seems simple, but I fail to solve it. Anybody who can help with country array? Right now the following code is active, which limits the available country to US only, for a certain language/area selection. It works fine. I would now only like to include an additional country (CA) as a choice besides US for the same language/area selection (without changing the language/area selection). If anyone knows the trick pls help. Existing Code:
if( !function_exists('filter_woocommerce_countries_shipping_countries') ) {
Hello I am trying to show/geo target content for certian countries that my visitors to my site are from. I have doing a little research on google and have found a few script but for some reason they do not work. I know about the geoip database from maxmind but I am looking for a remote solution as the geoip database is said to be a heavy strain on servers if you get a lot of visitors. I am hosted on a shared server so I do not want to get my account suspended for over working the server. Also I have a few sites that will use this idea. This is a script I found whilst googling and all it does is give me an error. Code: [Select] <?php $ip = $_SERVER [ 'REMOTE_ADDR' ]; $country = file_get_contents ( 'http://api.hostip.info/country.php?ip=' . $ip ); if ( $country == "US" ) { echo "<American-English Ringtone Ad Tag>" ; } elseif ( $country == "AU" OR $country == "UK" OR $country == "IE" ) { echo "<British-English Ringtone Ad Tag>" ; } else { echo "<YPN Ad Tag>" ; } ?> This is the error it gives me:- Quote Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/username/public_html/webaddress.co.uk/test/test.php on line 7 What I am trying to do is to geo target Javascript ads for different countries. When I add the javascript ad it gives me that error. If I just put in normal text then it works ok. Thank you all for your help in advance. Okay we are using a javascript, but the javascript that the site comes from has bans all irans ips... and it loads slow for those people, how would I place a if statement saying dont load this javascript if in Iran, thanks... I know how to do it, but I can't find a real set number, and I would use just 1 ip but the guy has dynamic... thanks ahead of time same with trivago Welcome to www.trivago.com. trivago is available locally: Continue to trivago Australia or Stay on www.trivago.com Hello from the UK! We want to make sure you get to the right place, and noticed you appear to be visiting us from Australia. If you would prefer to visit our Australian site, please just follow the link below. Go to our Australian site comparethemarket.com.auhi professionals I was not sure where to exactly post this as I am not to sure if it is a php question. We are developing a new website for another country and are looking to geo target people with the country in mind for instance if I visit comparethemarket .com or comparethemarket uk from here in Australia a pop up window appears saying the following I'm trying to block access to a particular page if the visitor is not from a specific country (using Maxmind Geoip Country database), but not quite sure how to code this properly: I tried this and many variations of this inside the head tags, bud doesn't work. Any suggestions on the best way to go about this? Code: [Select] <?php require_once("geoip.inc"); $gi = geoip_open("/home/username/GeoIP.dat",GEOIP_STANDARD); $country_code = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']); geoip_close($gi); if($country_code !== 'US') header("HTTP/1.0 404 Not Found"); exit; ?> hey guys just wondering what u think the best way to do this.....on my form registration for users....I have a drop down for countrys....but I dont want to have 2 drop downs 1 for state and 1 for province if they choose canada/usa....I have seen alot of java scrit on such sites where if you choose Canada for country, then it switches to a drop down for just provinces, not states. Same for zip code/postal code...american zip code would be like 90210 where as a postal code would be like n5j2S1. Is there a script or something already I can use with all the countrys/provinces/states etc already entered so im not re-inventing the wheel here? If someone can point me in right directon id appreciate it. Thanks Hi, I have a search form where users can search by age and country. Users can also save their search so they can go back and do it again but the problem is when they reload their saved search, I need it to select the country that has been saved in the drop down. So if someone searched the United Kingdom, I need it to show United Kingdom in the select drop down instead of (Select Country). Is there any easy and quick way around this? Many Thanks I can seem to login it tells me to check my password and username but i dont know the username and password are correct
here is my whole code
<?php //start the sessoin session_start(); //connect to db require "scripts/connect.php"; $username = $_POST['username']; $password = $_POST['password']; $username = mysqli_real_escape_string($db,$username); $password = mysqli_real_escape_string($db,$password); if(isset($_POST['loginbtn'])){ if(!empty($username) && !empty($password)){ //sql command $getstaff = "SELECT * FROM `users` WHERE `username` = '$username'"; //execute the query $query = mysqli_query($db,$getstaff); //get the number of rows $num_rows = mysqli_num_rows($query); if($num_rows != 0){ //get the info $rows = mysqli_fetch_assoc($query); //setting the data in indivaul variables $dbusername = $rows['username']; $dbpassword = $rows['password']; //getting the password the user enter and making it hash //in order for it to match in the database $password = md5($password); if($dbusername === $username && $dbpassword === $password){ //create the session $_SESSION['username'] = $username; //redircet them to the control panel header("location: controlpanel.php"); }else $msg = "Please check your username or password"; }else $msg = "User does not exist"; }else $msg = "Please enter your username and password"; } ?>This is where it is giving me a hard time if($dbusername === $username && $dbpassword === $password){ //create the session $_SESSION['username'] = $username; //redircet them to the control panel header("location: controlpanel.php"); }else $msg = "Please check your username or password";Any ideas why its not letting me enter I have built a simple website to share photos with people at work. And it is based on code - known to work - from a larger website that I built a few years ago. When you land on the site, you have a login screen, and if the username/password match what is hardcoded, then I set $_SESSION['loggedIn'] = TRUE; and I redirect to the menu.php page. If your credentials do not match, then I redirect the user to an access-denied.php (403) page. Here is the problem... Occasionally, when you try to log in you will get routed to the access-denied page. But then if you try a second time you end on on the menu page. I uploaded my otherwise working code to my hosted webserver, and now I can never seem to log in. It seems to me that something is getting screwed up with the session variable? Any ideas what could be causing this strange behavior? Hi guys, I got a little bit of an issue. I have a register page, which works fine and submits to itsself, however i also have a login page which currently has no errors but doesnt allow any1 to log in. If some1 can see why that will be great, as this is causing so many issues. This is the last step i cant get past. Here is the code Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title>Forensics E-learning Package</title> <script type="text/javascript" src="start.js"></script> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <div id="wrapper"> <div id="header"> <div id="toplinks"> </div> </div> <div id="menu"> <ul> <li><a class="selected" href="index.html">Home</a></li> <li><a href="index.php">Initial Quiz</a></li> <li><a href="about.php">About</a></li> <li><a href="member.php">Member Section</a></li> </ul> </div> <div id="content"> <div id="main"> <h1>Forensics E-Learning Package</h1><BR /></head> Login to the User Profiled E-Learning Course which is specifically aimed to raise awareness in computer forensics. <?php $submit =&$_POST['submit']; if(isset($submit)) { if($username && sha1($password)) { $username =&$_POST['username']; $password =&$_POST['password']; $_SESSION['$username'] = $username; $_SESSION['$password'] = sha1($password); $connect = mysql_connect("localhost","root", "") or die ("Couldn't Connect!"); mysql_select_db("userlogin", $connect) or die("Couldn't find db"); //$con = mysql_connect('userscores.db.7767668.hostedresource.com','userscores','L3tt3r09'); //mysql_select_db('userscores', $con); $query = mysql_query("SELECT * FROM users WHERE username=' $username'"); $numrows = mysql_num_rows($query); if ($numrows!=0) { //code to login while ($row = mysql_fetch_assoc($query)) { $dbusername = $row['username']; $dbpassword = $row['password']; $dbscore = $row['score']; $dbdclty = $row['dclty']; $dbid = $row['id']; $dbnewdclty = $row['newdclty']; } $_SESSION['id'] = $dbid; $_SESSION['PreviousScore'] = $dbscore; $_SESSION['dclty'] = $dbdclty; $_SESSION['newdclty'] = $dbnewdclty; if ($username==$dbusername&&sha1($password)==$dbpassword) { $username==$dbusername; } else { echo ("Incorrect Password!"); } } else { echo("That user doesn't exist!"); } } else { echo("Please enter a username and password!"); } echo ("You Successfully Logged In!"); } else { ?><BR /><BR /><?php echo("Please Log In!"); } if ($submit) echo "Logged In Successfully!"; ?> <BR /><BR /> <form action='index.php' method='POST'> Username: <input type='text' name='username'><BR /> Password: <input type='password' name='password'><BR /> <input type='submit' value='Log In'> </form> <p><BR /><BR /> <a class="button" href='register.php'><span><button class="button" id="save">Register</button></span></a> </div> <div id="right"> <h2>Right Menu</h2> <div class="rightitem"> <ul> <li><a class="selected" href="index.html">Home</a></li> <li><a href="index.php">Initial Quiz</a></li> <li><a href="about.php">About</a></li> <li><a href="member.php">Members Area</a></li> <li><a href="contact.php">Leave Feedback</a></li> </ul> </div> </div> </div> <div class="clearbottom"></div> <div id="footer"></div></div> </body> </html> Thanks for any help Lance After getting my site hacked, I'm not really up for learning PhP, so I'm trying to use uMScript.
On the demo site, and when I just load up the files on my server, it will redirect upon log in. But when I then use my styling, for some reason the login_submit.php gives me a blank page and does not redirect, nor does it log the user in. I don't change anything except the positioning of the forum and the container around it, no PhP or JS changes, weird? I can not seem to get a hold of the creator, nor can I find a user script that matches what I'm looking for. Heck, I'm so close to going mad, I'm even willing to pay someone to do the user PhP for me haha Has anyone used this script successfully? You can try it out he http://mod-universe.com/index.php Demo: http://www.ventureha.../demo/index.php (I couldn't get the demo credentials to log in, created a new user = Okriani, kieran09) will the following code work to log any php errors i may have on the page this code is included? Code: [Select] ini_set('error_reporting', E_ALL); error_reporting(E_ALL); ini_set('log_errors',TRUE); ini_set('html_errors',FALSE); ini_set('error_log','./error_log.txt'); ini_set('display_errors',FALSE); |