Archive for the ‘Uncategorized’ Category

Drupal ip2nation block module code

ok afterlooking for a while for help with drupal ip2nation: here is a samle module that will allow you to display a block with custom content – per country in drupal 6.X

<?php
function mymod_block($op=’list’, $delta=0) {
// set up the block
$block = array();

if ($op == “list”) {
// Generate listing of blocks from this module, for the admin/block page

$block[0]["info"] = t(‘Ip2nation – Custom’);
}
else if ($op == ‘view’) {

// Generate our block content

// content variable that will be returned for display
$block_content = ”;

$ip= $_SERVER['REMOTE_ADDR'];
if ($ip == “127.0.0.1″) {
// default ip for australia as japan is in db for local host
$ip =”110.142.15.249″;
}

$sql = “SELECT c.country “;
$sql .= “FROM {ip2nationCountries} c “;
$sql .= “INNER JOIN {ip2nation} i ON c.code = i.country “;
$sql .= “WHERE i.ip < INET_ATON(‘%s’) “;
$sql .= “ORDER BY i.ip DESC “;
$sql .= “LIMIT 0,1″;

// $query_result =  db_fetch_object(db_query($sql, $ip));
$query_result =  db_query($sql, $ip);
while ($thecountry = db_fetch_object($query_result)) {

$theusercountry = $thecountry->country;
switch ($theusercountry) {
case “Australia”:
$myresult=’<img src=”Australiaimage.jpg”>’;
break;
case “Canada”:
$myresult=” You Are In Canada “;
break;

default:
$myresult = “You Are Global”;
}

//$block_content .= ‘ ‘.$ip.’<b/>’.var_dump($query_result).’ :’;
//$block_content .=$thecountry->country.’ ‘;

$block_content .= $myresult;

}

// Fill in the subject of our block which is the same whether or not
// the block has any real content
$block['subject'] = ‘ip2nation custom’;

// check to see if there was any content before returning
//  the block view
if ($block_content == ”) {
// no content make default
$block['content'] = $myresult;
}
else {
// set up the block
$block['content'] = $block_content;
}
}

return $block;
}  // end block

?>

Asp.net VB Textbox to Sql

Ok I have visual Studio web developer and I have a database now what
it is some times frustrating to find custom SQL in Asp.net tutorials , you always get the same thing how to data bind , grid views ect but what if you just want to go from a text box control to a sql insert ? well it is pretty easy if you know where to start … in visual studio Web developer  first make a database table and include an id and set it as a primary key and a text field Varchar  lets call it “name” varchar (50) add some data to it then drag a good old fashion text box control and button on to a new Asp.net page then you will need to add a New  SqlDataSource on the page ,  connect to it then next then click advanced . and tick generate insert, update, Delete statements…and ok then finish now that you have all that click on the button to make an event handler

In VB.. Add this script to the event handler

SqlDataSource1.InsertParameters(“name”).DefaultValue = textbox1.Text.ToString()

SqlDataSource1.Insert()

DONE ! then you can see that your data has been inserted in to the table why not ad a grid view to test this below it
assuming you have an table and with id set to primary key and “name”
Example

Default.aspx:

<%@ Page Language=”VB” AutoEventWireup=”false” CodeFile=”again.aspx.vb” Inherits=”again” %>

<!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 runat=”server”>
<title> </title>
</head>
<body>

<form id=”form1″ runat=”server”>

<div>

Name

<asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox>

<asp:Button ID=”Button1″ runat=”server” Text=”Button” />

<br />

<asp:SqlDataSource ID=”SqlDataSource1″ runat=”server”

ConnectionString=”<%$ ConnectionStrings:customsiteConnectionString2 %>”

DeleteCommand=”DELETE FROM [mysimpletable] WHERE [id] = @id”

InsertCommand=”INSERT INTO [mysimpletable] ([name]) VALUES (@name)”

SelectCommand=”SELECT * FROM [mysimpletable]”

UpdateCommand=”UPDATE [mysimpletable] SET [name] = @name WHERE [id] = @id”>

<DeleteParameters>

<asp:Parameter Name=”id” Type=”Int32″ />

</DeleteParameters>

<InsertParameters>

<asp:Parameter Name=”name” Type=”String” />

</InsertParameters>

<UpdateParameters>

<asp:Parameter Name=”name” Type=”String” />

<asp:Parameter Name=”id” Type=”Int32″ />

</UpdateParameters>

</asp:SqlDataSource>

</div>

</form>

</body>

</html>

Default.Asp.VB:

Partial Class again

Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

SqlDataSource1.InsertParameters(“name”).DefaultValue = TextBox1.Text.ToString()

SqlDataSource1.Insert()

End Sub

End Class

and that is it not to bad

Ajex Is Easy

A lot of people don’t know the basics of ajex : or passing vars from a page and using JavaScript to call another asp/php/asp.net/javascript page … I f you know php or asp or asp.net and JavaScript event handlers then my friend you are ready to start making use of simple then more advanced Ajax like web interfaces … lts here is a fun simple example :

the “magic” takes place with the JavaScript  XMLHttpRequest()

Put this in the head section of a html / php page

<head>
<title>Some Document </title>
<script type="text/javascript">
function loadXMLDoc(int)
{
if (window.XMLHttpRequest)
 {// code for IE7+, Firefox, Chrome, Opera, Safari
 xmlhttp=new XMLHttpRequest();
 }
else
 {// code for IE6, IE5
 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 }
xmlhttp.onreadystatechange=function()
 {
 if (xmlhttp.readyState==4 && xmlhttp.status==200)
 {
 document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
 }
 }
xmlhttp.open("GET","result.php?var="+int,true);
xmlhttp.send();
}
function changecolour(){
document.getElementById("change").style.color="red"
}
</script>
</head>
that gets it going note it will call a php page called result.php with a url encode ?var= the javascript var 

 <div id="myDiv"><h2>Let AJAX see if you type hello</h2>
<br />

 <input type="text"  onblur="loadXMLDoc(this.value)"/>
 </div>
(note just type hello) then make a new page called
result.php... and in it put this in it
<?php
$thevar = $_GET['var'];
echo $_GET['var'];
if($_GET['var'] =="hello"){
// could be password validation or what ever
echo "You Typed hello You Are Cool";
$x=1;
}else{
echo"<br/>
<input type='text' value='".$thevar."' style='color:#FF0000'  onblur='loadXMLDoc(this.value)'/> \n";
echo" <br/>Not valid please try again just type `Hello` ";
}
?>
there you go job done you can do any thing in that result page
download example here and have fun 

once you have this idea you can easily see how you can use
(real)  xml to communicate between many applications

Allot of people don’t know the basics of ajex : or passing vars from a page and using JavaScript to call another asp/php/asp.net/javascript  page …

I f you know php or asp or asp.net and JavaScript event handlers then my friend you are ready to start making use of simple then more advanced Ajax like web interfaces … lts here is a fun simple example :

the “magic” takes place with the XMLHttpRequest()

How To Display Content Based on Ip (Geolocation)

Let me show you how to do Geolocation  Content based on ip address !(with php and mysql)
first you need a database eg make  a database  call it what ever you want now you will need to Get A Database of ip 80% world wide accuriate  Click Here to download ( ip2nation )

Then insert import the sql (taken from ip2nation but small changes)

note Go to http://ip2nation.com/ip2nation/Sample_Scripts
and Get it …the bottom of code is different examples of use

<?php
////////////////dot use this get it from ip2nation.com
	$server   = ''; // MySQL hostname
	$username = ''; // MySQL username
	$password = ''; // MySQL password
	$dbname   = ''; // MySQL db name
$table = "ip2nation";
	$db = mysql_connect($server, $username, $password) or die(mysql_error());
	      mysql_select_db($dbname) or die(mysql_error());
	$sql = 'SELECT `country`FROM
	            `$table`
	        WHERE
	            `ip` < INET_ATON("'.$_SERVER['REMOTE_ADDR'].'")
	        ORDER BY
	            `ip` DESC
	        LIMIT 0,1';

	list($country) = mysql_fetch_row(mysql_query($sql));
// use a switch statement for redirect
	switch ($country) {
		case 'ca':
			// Get the Canadians to a canadians site
			header('Location: http://www.yoursite.ca/');
			exit;
		case 'us':
			// And redirect US visitors to your .com
			header('Location: http://www.yoursite.com/');
	exit;
		default:
			// The rest of the world can go to defult
			header('Location: http://www.yoursite.com.au/');
			exit;
	}
//Get The Basic Idea include a file
if($country = 'ca'){
include ("canada.php");
}else{
include ("USA.php");
}
// Display an image
switch ($country) {
case 'ca':
// show canada flag

echo"<img src='images/canada.jpg' />";
exit;
case 'us':
// show us flag
echo"<img src='images/usa.jpg' />";
exit;
default:// the default flag
echo"<img src='images/australia.jpg' />";');
}
?>

try it
http://taggartjensen.com/ip
Have Fun this demo is for  Australia, Canada, Usa

Subscription

Fill out the form below to signup to my newsletter and You Can Get New Cool free Scripts , advice ...ect

Our strict privacy policy keeps your email address 100% safe & secure.



























Ads1



Designed by Taggart Jensen .