cwarn23 387 Occupation: Genius Team Colleague Featured Poster

I wonder how long until they invent replicators. Replicators would be able to wipe out the robots with no problem. Or what about hackers hacking into a robot network. A hacker could send a Trojan to all robots in the United States and give those robots the command to destroy everything in sight. G' the future hackers have a lot more to play with...

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

If your going to do that then I would suggest the following:

<img src="http://<?php echo urlencode($_GET['code']); ?>.example.com/<?php echo urlencode($_GET['id']); ?>">

That will stop xss attacks.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Do you mean like this?

<?php
$variable='i45';
echo '<img src="http://'.$variable.'.expamle.com/'.urlencode($_GET['code']).'">';
?>
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Hello Kyle, thanks a lot for your reply.

I'm not placing my php scripts in the cgi-bin/php folder, my scripts are inside the folder structure of my website. As you say, they were executed fine anywhere in the server when I had my website in another hosting so I thought this would be the case in this new hosting aso, but for some reason it isn't.

Anyway, I tried copying the php scripts in the cgi-bin/php folder, but still it's not working because it is trying to find the whole path following the folder. For instance, if the script is in:

www.mywebsite.com/edition/myscript.php

it is trying to execute:

cgi-bin/php/mywebsite.com/edition/myscript.php

which of course can't find.

I'm really lost here...

Why don't you move the php folder out of the cgi-bin and place it at the proper location so the url's dont need rewriting. Also having php files in a cgi-bin can cause problems as for example the server may treat the php files as cgi/perl files. And permissions are different in the cgi-bin directory resulting in possible productivity loss. So I would suggest moving those files to a place where they wont need rewriting to.

Altairzq commented: Thank you! +0
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

So my question is, "Does the browser have an effect on the type of a file uploaded?"

Yes because if you go into the Opera preferences you will see that Opera will only recognize web related mime types. Other mime types are not programmed into Opera where as a browser like firefox may use the windows file system to recognize file types.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Line 19 and 20 should be replaced with the following.

if (mail($to, $subject, $message, $headers))

Also if you want to check the results in your cgi script then it would be as simple as comparing the return value. Eg.

if ($result=='Success the email was sent.') {
//success message
} else {
//fail message
}
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

At login.php, when i echo the session data that was passed it is null. Why.?

Do you have cookies enabled? Also does $_POST exist? And is $_POST a radio button? You need cookies enabled for sessions to work and as for radio buttons, sometimes they will return null if no option is selected or not used properly. I would suggest checking if $_POST has the same value as $_SESSION.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Try make action="success.php" and in success.php place the following code.

$url = 'http://www.mywebsite.com/cgi-bin/cgiemail/form/form.txt';

//url-ify the data for the POST
foreach($_POST as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);

That should forward the post to your other action.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Then you would set it for a really big number like

$ExpireTime = (time() + 999999999);

That is about as long as you can set a cookie before hitting the Unix timestamp bug and will last till the year 2037.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster
if ($TheCookie[3] == 1) {
			$ExpireTime 
 
= time() + 31536000;
		} else {
			$ExpireTime 
 
= 0;
		}

The latest version of php is 5.3 although I would recommend version 5.2. Also try replacing the above with the below.

$ExpireTime = (time() + 31536000);

So to completely remove the if statement and just place that line there to see if that will set the cookie.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

No it didnt work... Let me explain how the login works a little better... When you login it gives you the right to view pages that you couldnt view if you werent logged in. Like if you log in you can go to overview.php but if your not logged in then it redirects you back to login. I tried to go to overview with the code you gave me but it didnt work... Is it possible it uses something else to set the cookie?

I have heard that it is possible to use javascript or even java to set cookies but I wouldn't recommend it because if a user has javascript disabled then the cookie will not be set. This is an unusual bug and may I ask what version of php you have?

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Try setting line 57 of Mauzam's script to the following

$expiretime = (time()+((3600*24)*30))
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Do you only have the one cookieset function because the code in Muazam's post looks very correct.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

That didnt work... when i went to the page that you need to be logged into to view it just redirected me to login.php thanks for trying though....

Have you set your browser to delete your cookies when you close your browser. I would check your cookie preferences in your web browser and make sure cookies do not get deleted by the browser. I think that is the key to the problem.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

you know what takeshi.... im so sick and tired of debugging your code... i had help you many times and even provided code in many of your threads but you didn't had even the effort to payback the guys that helped you. You dont mark you thread solved. You just come here and beg for answers which is very annoying that some solutions are simple and obvious. i think your so lazy that your just copy and paste the code without even understanding it. Were like baby spoon feeding you here. Grow up and do you assignments on your own. You wont learn anything if you dont put your effort on it. I hope i make sense to you.

One of the best ways of learning is by asking for help and as long as you learn from that help then next time they should be able to solve the same problem by themselves.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Perhaps this will work...

<?php
  
      mysql_connect ("localhost", "root",'password') or die (mysql_error());

      mysql_select_db ("records");

      $criteria = (int)$_POST['criteria'];

      $sql = "SELECT * FROM students WHERE ";

      switch($criteria)

      case 1: $sql .= "course"; break;

      case 2: $sql .= "surname"; break;

      case 3: $sql .= "department"; break;
 
      case 4: $sql .= "email"; break;

      case 5: $sql .= "studno"; break;

      }
 
      $sql .= " LIKE '%term%'";
      $r=mysql_query($sql) or die(mysql_error());
      while ($row = mysql_fetch_assoc($r)){

       
  
      echo '<br/> Surname: '.$row['lname'];

      echo '<br/> Course: '.$row['course'];

      echo '<br/> Student No: '.$row['studno'];

      echo '<br/> Department: '.$row['department'];
 
      echo '<br/> Email Address: '.$row['email'];
 
      }
 
      ?>
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

The linked thread still barfs...

Same here and when I tried to post pi to 10000 digits it also said the server was out of memory. Annoying error.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

The best way to have a short and easy to remember password is by having a password like the following ¢£¤¥¦§ or even the whole ascii table like the following

!"#
$%&'()*+,-./0123
456789:;<=>?@ABC
DEFGHIJKLMNOPQRS
TUVWXYZ[\]^_`abc
defghijklmnopqrs
tuvwxyz{|}~€‚ƒ
„…†‡ˆ‰Š‹ŒŽ‘’“
”•–—˜™š›œžŸ ¡¢£
¤¥¦§¨©ª«¬®¯°±²³
´µ¶·¸¹º»¼½¾¿ÀÁÂÃ
ÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓ
ÔÕÖרÙÚÛÜÝÞßàáâã
äåæçèéêëìíîïðñòó
ôõö÷øùúûüýþÿ

Who has a password like the above? Now that's the uncrackable. But as for a side note, has any site made an alternative to passwords because I heard there was a debate if passwords should be depreciated but obviously never went ahead. (No reply expected) I myself am developing an alternative system where you click colors to make your password as then it can never be weak. Also have you heard of passwords like the following

qwerty
itunes!
internet
mycomputer
c++rox
c++rox!

A list of simple passwords. I wonder if anybody has made a list like that because just like calculating pi anybody could spend half their life writing out possible passwords. But yea, I've heard of some of the passwords people use and makes me wonder why do they bother using a password.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

This is a hard question which I paid good money to solve. You need to download the library(s) source (eg the GD Source) then upload the source code to your server. After that you need to compile the source into the webserver via command line and when your finished that you then restart or start apache. That's the basic concept but I have no idea on how to compile the source.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

This is not a PHP function. It is likely that you have an included file or code somewhere which defines this.

Indeed because if you go into the official documentation and manually put the function into the url a 404 comes up and when searching the official documentation it does not appear. /manual/en/function.tabs.php
Try your code without including any files and I bet the function will not exist.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

I would suggest the following:

$zone=array('id'=>array(),'name'=>array());
while ($row=mysql_fetch_assoc($result)) {
$zone['id'][]=$row['zone_id'];
$zone['name'][]=$row['zone_name'];
}
//first index
echo $zone['id'][0];
echo $zone['name'][0];
//second index
echo $zone['id'][1];
echo $zone['name'][1];

How be sure that not much data is being stored in the array (>1MB) as you can make your script run out of memory.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

The results of the three "echo" statements are as follows:
Regen remainder: 57
Current time: 1264322357
1.2643223E+09

This is a limitation in the computing world (64 and 32 bit processors). They can only store so many numbers before showing all weird things. Fortunately php has a way around this. When doing math for large numbers try using the bcmath library. This will store the numbers as strings and process the numbers as strings. Then you may have infinit sized numbers. If you like post your full code and I shall try to implement it for you.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Not supporting every language. Below are the codes for each language. Did you use these short codes?

ar = Arabic
bg = Bulgarian
ca = Catalan
zh-CN = Chinese
hr = Croatian
cs = Czech
da = Danish
nl = Dutch
en = English
tl = Filipino
fi = Finnish
fr = French
de = German
el = Greek
iw = Hebrew
hi = Hindi
id = Indonesian
it = Italian
ja = Japanese
ko = Korean
lv = Latvian
lt = Lithuanian
no = Norwegian
pl = Polish
pt = Portuguese
ro = Romanian
ru = Russian
sr = Serbian
sk = Slovak
sl = Slovenian
es = Spanish
sv = Swedish
uk = Ukrainian
vi = Vietnamese
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

i have a small doubt. phpcode works in this? i am using php for retriving data from database in html . is it works? i tried but colors not changing.

Well remember not to put the <script></script> tag into that function as it can't filter javascript (only html).

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Would this do the trick?

<?php
    if (!isset($_GET['language']) || empty($_GET['language'])) {
    $_GET['language']='en';
    }
    class Google_Translate_API {
 
	/**
	 * Translate a piece of text with the Google Translate API
	 * @return String
	 * @param $text String
	 * @param $from String[optional] Original language of $text. An empty String will let google decide the language of origin
	 * @param $to String[optional] Language to translate $text to
	 */
	function translate($text, $from = '', $to = 'en') {
		$url = 'http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q='.rawurlencode($text).'&langpair='.rawurlencode($from.'|'.$to);
		$response = file_get_contents(
			$url,
			null,
			stream_context_create(
				array(
					'http'=>array(
					'method'=>"GET",
					'header'=>"Referer: http://".$_SERVER['HTTP_HOST']."/\r\n"
					)
				)
			)
		);
		if (preg_match("/{\"translatedText\":\"([^\"]+)\"/i", $response, $matches)) {
			return self::_unescapeUTF8EscapeSeq($matches[1]);
		}
		return false;
	}
 
	/**
	 * Convert UTF-8 Escape sequences in a string to UTF-8 Bytes
	 * @return UTF-8 String
	 * @param $str String
	 */
	function _unescapeUTF8EscapeSeq($str) {
		return preg_replace_callback("/\\\u([0-9a-f]{4})/i", create_function('$matches', 'return html_entity_decode(\'&#x\'.$matches[1].\';\', ENT_NOQUOTES, \'UTF-8\');'), $str);
	}
}
 
 
function display($input) {
$trans_text = Google_Translate_API::translate($input, '', $_GET['language']);
    if ($trans_text !== false) {
        return $trans_text;
    }}
function displayhtml($input) {
    preg_match_all('#<[^>]+>#',$input,$htmlout);
    $input=preg_split('#<[^>]+>#',$input);
    $output='';
    $i=0;
    foreach ($input AS $val) {
        $output.=str_replace(array('\r','\n'),array("\r","\n"),display($val)).$htmlout[0][$i];
        $i++;
        }
    return $output;
    }
echo displayhtml('<!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=iso-8859-1" />
<title>Untitled Document</title>
</head>
 
<body>
 <form name="language" action="'.$_SERVER['PHP_SELF'].'" method="GET">
	<select onchange = "document.language.submit()"  name="language">
  	<option selected="selected"> select-language</option>
       <option value="en"> English</option>
     <option value="es"> Spanish</option>
       <option value="fr"> French</option>
    </select>
	<p class="normal_text">A woman`s body performing to its utmost capability- that`s what pregnancy is. From conception to delivery, the female form is tried and tested to carry and bring forth new life. …
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

haaaa.............haaaaa....it is very complecated procedure. it is not easy to do. very carefully do this.
there is no other option for this echo ing each and every html tag.
otherwise take in php function in class and using this class call this funtion where ever we want that function.
is it possible?
why b'coz i have to do convert more html pages.

It might be possible to use regex to convert all the data in the one hit but could be hard to make. Could you post an example file which includes these complex javascripts.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

It would require javascript but as for the basics I believe it would be something like the following.

<table>
<tr onclick=javascript:showrow(1)><td></td><td id="1"></td></tr>
<tr onclick=javascript:showrow(2)><td></td><td id="2"></td></tr>

Then you would use css to hide the rows and a custom javascript function to show the rows. Hope that helps.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

how to write echo for javascript with in the php code? for suppose in above example may have javascript so how to write echo for that?

Could you give an example. From my understanding it would be as follows.

<?php
echo '<script>'."\n";
echo 'document.write("';
display('some text');
echo '");'."\n";
echo '</script>';
?>
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

The table name and fields that have spaces in the name must be inclosed in single quotes:

INSERT INTO 'employee record'('Employee ID', 'Employee type', 'First Name', 'Last name', 'Farm location', 'Farm type') VALUES('34', 'caretaker', 'Michael', 'Hipolito', 'lara', 'nursery' )

I could be wrong but don't column names and tables have a different type of quote like the following?

INSERT INTO `employee record`(`Employee ID`, `Employee type`, `First Name`, `Last name`, `Farm location`, `Farm type`) VALUES('34', 'caretaker', 'Michael', 'Hipolito', 'lara', 'nursery' )
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

So is it solved?

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

U bothe are useing same technique. Don t use insertion and display in same loop

I assumed the echo was being used as a test and that the insertation was the real deal. But yes recording mysql data into an array should be avoided whenever possible.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Try the following.

<?php
$resultSN = mysql_query("SELECT * FROM table ") or die(mysql_error());
$count=mysql_num_rows($resultSN);
$machineName=array();
while($row = mysql_fetch_assoc($resultSN))
{
   $machineName_O = $row['MachineName'];

     for ($i=0; $i<$count; $i++)
     {
	$machineName[] = $machineName_O;
	echo $i. " " . $machineName_O . "<br>";
    }
}
?>
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Try placing this at the top of each page.

<?php
session_start();
if (!empty($_GET)) {
for ($i=0;$i<count($_SESSION['GET']);$i++) {
    if ($_SESSION['GET'][$i]==$_GET) {
        die('This page has already been viewed.');
        }
    }
$_SESSION['GET'][]=$_GET;
}
?>
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

As far as I know it isn't possible to removes ones url history but perhaps you should consider $_POST. Then the user will need to confirm the post request and if they do you should then get the server to check if the same post request has been sent in the last 48 hours. Mysql or maybe even sessions could help you there. If you could post some code then I will help you implement these features.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Try making this your query and see what error mysql reports back.

$qry = "SELECT `userid`, COUNT(*) as `cnt` FROM table1, table2 WHERE userid = id GROUP BY userid ORDER BY cnt DESC LIMIT 0,10";
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

I would suggest following the manual at http://www.php.net/manual/en/image.requirements.php

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Well copy and past the code in post #10 then as a test load that exact file on your browser (without any other code/files) to test if you have the gd library installed. Then see if there are any error messages when opening the file directly.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Sorry for the late reply. To run it just copy the above code into a separate file. Then in your main file place the following code.

<?php
echo '<img src="graphgenerator.php">';
?>

Then it should generate the graph as an image using the script above. And note graphgenerator.php is the code in post #10.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

is it problem when retrivinng data from database.

As long as you don't put html code inside the display function it should work fine.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Try this.

<?
if (!isset($_GET['language']) || empty($_GET['language'])) {
$_GET['language']='en';
}
/**
 * Translating language with Google API
 * @author gabe@fijiwebdesign.com
 * @version $id$
 * @license - Share-Alike 3.0 (http://creativecommons.org/licenses/by-sa/3.0/)
 * 
 * Google requires attribution for their Language API, please see: http://code.google.com/apis/ajaxlanguage/documentation/#Branding
 * 
 */
class Google_Translate_API {

	/**
	 * Translate a piece of text with the Google Translate API
	 * @return String
	 * @param $text String
	 * @param $from String[optional] Original language of $text. An empty String will let google decide the language of origin
	 * @param $to String[optional] Language to translate $text to
	 */
	function translate($text, $from = '', $to = 'en') {
		$url = 'http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q='.rawurlencode($text).'&langpair='.rawurlencode($from.'|'.$to);
		$response = file_get_contents(
			$url,
			null,
			stream_context_create(
				array(
					'http'=>array(
					'method'=>"GET",
					'header'=>"Referer: http://".$_SERVER['HTTP_HOST']."/\r\n"
					)
				)
			)
		);
		if (preg_match("/{\"translatedText\":\"([^\"]+)\"/i", $response, $matches)) {
			return self::_unescapeUTF8EscapeSeq($matches[1]);
		}
		return false;
	}
	
	/**
	 * Convert UTF-8 Escape sequences in a string to UTF-8 Bytes
	 * @return UTF-8 String
	 * @param $str String
	 */
	function _unescapeUTF8EscapeSeq($str) {
		return preg_replace_callback("/\\\u([0-9a-f]{4})/i", create_function('$matches', 'return html_entity_decode(\'&#x\'.$matches[1].\';\', ENT_NOQUOTES, \'UTF-8\');'), $str);
	}
}


$input= "http://localhost/addmultiplelanguajes-2009-08-15/k1.php";
function display($input) {
$trans_text = Google_Translate_API::translate($input, '', $_GET['language']);
    if ($trans_text !== false) {
        echo $trans_text;
    }
}




echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";
echo '<html xmlns="http://www.w3.org/1999/xhtml">'."\n";
echo '<head>'."\n";
echo '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />'."\n";
echo '<title>'; display('Untitled Document'); echo '</title>'."\n";
echo '</head>'."\n";
echo "\n";
echo '<body>'."\n";
echo '<form name="language" action="'.$_SERVER['PHP_SELF'].'" method="GET">'."\n";
echo '	<select onchange = "document.language.submit()"  name="language">'."\n";
echo '    	<option selected="selected">'; display('select-language'); echo '</option>'."\n";
echo ' …
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Try this code:

<?php
$values=array(32,76,34,65,62,29,54,23,29,34);
//above is an array of values for the chart

//image size
$image_width=320;
$image_height=240;

//line thickness
$line_thickness=3;

//line color
$line_color['r']=0;
$line_color['g']=0;
$line_color['b']=0;

//background color
$bg_color['r']=255;
$bg_color['g']=255;
$bg_color['b']=255;


//raw code
function imagelinethick($image, $x1, $y1, $x2, $y2, $color, $thick = 1)
{
    /* this way it works well only for orthogonal lines
    imagesetthickness($image, $thick);
    return imageline($image, $x1, $y1, $x2, $y2, $color);
    */
    if ($thick == 1) {
        return imageline($image, $x1, $y1, $x2, $y2, $color);
    }
    $t = $thick / 2 - 0.5;
    if ($x1 == $x2 || $y1 == $y2) {
        return imagefilledrectangle($image, round(min($x1, $x2) - $t), round(min($y1, $y2) - $t), round(max($x1, $x2) + $t), round(max($y1, $y2) + $t), $color);
    }
    $k = ($y2 - $y1) / ($x2 - $x1); //y = kx + q
    $a = $t / sqrt(1 + pow($k, 2));
    $points = array(
        round($x1 - (1+$k)*$a), round($y1 + (1-$k)*$a),
        round($x1 - (1-$k)*$a), round($y1 - (1+$k)*$a),
        round($x2 + (1+$k)*$a), round($y2 - (1-$k)*$a),
        round($x2 + (1-$k)*$a), round($y2 + (1+$k)*$a),
    );
    imagefilledpolygon($image, $points, 4, $color);
    return imagepolygon($image, $points, 4, $color);
}

$img = @imagecreatetruecolor($image_width, $image_height);
imagefill($img, 0, 0, imagecolorallocate($img, $bg_color['r'], $bg_color['g'], $bg_color['b']));

$height_ratio=$image_height/max($values);
$width_ratio =$image_width/(count($values)-1);
$prev_x=-1;
$prev_y=-1;
for ($i=0;$i<count($values);$i++) {
if ($prev_x>-1 && $prev_y>-1) {
    imagelinethick($img, $prev_x, $prev_y, $i*$width_ratio, $values[$i]*$height_ratio, imagecolorallocate($img, $line_color['r'], $line_color['g'], $line_color['b']),$line_thickness);
    }
$prev_x=$i*$width_ratio;
$prev_y=$values[$i]*$height_ratio;
}
header ('Content-type: image/png');
imagepng($img);
imagedestroy($img);
?>

Note that the above code needs to be in a separate file and embedded as an image.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Why not use the translate function like the echo take so depending on the language input into the url it will translate to that language. Example:
URL=example.com/index.php?language=it

<?php
/**
 * Translating language with Google API
 * @author gabe@fijiwebdesign.com
 * @version $id$
 * @license - Share-Alike 3.0 (http://creativecommons.org/licenses/by-sa/3.0/)
 * 
 * Google requires attribution for their Language API, please see: http://code.google.com/apis/ajaxlanguage/documentation/#Branding
 * 
 */
class Google_Translate_API {

	/**
	 * Translate a piece of text with the Google Translate API
	 * @return String
	 * @param $text String
	 * @param $from String[optional] Original language of $text. An empty String will let google decide the language of origin
	 * @param $to String[optional] Language to translate $text to
	 */
	function translate($text, $from = '', $to = 'en') {
		$url = 'http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q='.rawurlencode($text).'&langpair='.rawurlencode($from.'|'.$to);
		$response = file_get_contents(
			$url,
			null,
			stream_context_create(
				array(
					'http'=>array(
					'method'=>"GET",
					'header'=>"Referer: http://".$_SERVER['HTTP_HOST']."/\r\n"
					)
				)
			)
		);
		if (preg_match("/{\"translatedText\":\"([^\"]+)\"/i", $response, $matches)) {
			return self::_unescapeUTF8EscapeSeq($matches[1]);
		}
		return false;
	}
	
	/**
	 * Convert UTF-8 Escape sequences in a string to UTF-8 Bytes
	 * @return UTF-8 String
	 * @param $str String
	 */
	function _unescapeUTF8EscapeSeq($str) {
		return preg_replace_callback("/\\\u([0-9a-f]{4})/i", create_function('$matches', 'return html_entity_decode(\'&#x\'.$matches[1].\';\', ENT_NOQUOTES, \'UTF-8\');'), $str);
	}
}



function display($input) {
$trans_text = Google_Translate_API::translate($input, '', $_GET['language']);
    if ($trans_text !== false) {
        echo $trans_text;
    }
}

//html still must use echo function
echo '<b>';
//now to echo non-html or text to translate
display("this is a test");
echo '</b>';

You will see at the bottom of that file how you can echo some text which will display …

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

hmmm..the GOOGLE API sirs is really great! and it does what i wanted it to do..however, the problem is that it needs internet connection for it to work, am i right? because that's what ive noticed, now, is there any solution to my problem? plotting data to a graph without having internet connection??

It is possible but hard. I have been planning for a while to write a tutorial on making charts using the php gd library but never got around to doing it. So today I shall make a start on it and hopefully will be done in time for you to read.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

You probably don't have curl installed but try the code in post #23. (My previous post). It should work without curl as long as your using php5.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

this is the scenario, i will plot the data in a graph coming from a live database, meaning the graph will change simultaneously according to the data..how is it possible?! please help me T_T

With the google api it is possible to make a html image tag then using url variables you dump your data into the end of the image tag. Below is an example:

<img src="http://chart.apis.google.com/chart?cht=lc&chd=t:27,40,100,72,40,84,44,76,48|10,8,8,6,6,6,5,9,3&chs=135x165&chl=Dec|Jan&chtt=Visits+this+month&chxt=x,y&chf=bg,s,FFFFFF&chco=000099,66CC00&chdl=Site|Page&chdlp=b">

That is a chart I have made using the google api and all you need to do is dump the data into the address. Read the link in my earlier post for more information.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

In php this could be kinda hard to do at first but there is an api by google you can use and is very handy. I've used this api myself and it seems pretty good with little or no limitations.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

I thought you'd near to cURL to avoid frame problem - anyway couldn't get your code to fly. Doesn't return anything.

Doesn't return anything... That annoying google making things difficult. digital-either made a good post some time ago and posted the following api.

/**
 * Translating language with Google API
 * @author gabe@fijiwebdesign.com
 * @version $id$
 * @license - Share-Alike 3.0 (http://creativecommons.org/licenses/by-sa/3.0/)
 * 
 * Google requires attribution for their Language API, please see: http://code.google.com/apis/ajaxlanguage/documentation/#Branding
 * 
 */
class Google_Translate_API {

	/**
	 * Translate a piece of text with the Google Translate API
	 * @return String
	 * @param $text String
	 * @param $from String[optional] Original language of $text. An empty String will let google decide the language of origin
	 * @param $to String[optional] Language to translate $text to
	 */
	function translate($text, $from = '', $to = 'en') {
		$url = 'http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q='.rawurlencode($text).'&langpair='.rawurlencode($from.'|'.$to);
		$response = file_get_contents(
			$url,
			null,
			stream_context_create(
				array(
					'http'=>array(
					'method'=>"GET",
					'header'=>"Referer: http://".$_SERVER['HTTP_HOST']."/\r\n"
					)
				)
			)
		);
		if (preg_match("/{\"translatedText\":\"([^\"]+)\"/i", $response, $matches)) {
			return self::_unescapeUTF8EscapeSeq($matches[1]);
		}
		return false;
	}
	
	/**
	 * Convert UTF-8 Escape sequences in a string to UTF-8 Bytes
	 * @return UTF-8 String
	 * @param $str String
	 */
	function _unescapeUTF8EscapeSeq($str) {
		return preg_replace_callback("/\\\u([0-9a-f]{4})/i", create_function('$matches', 'return html_entity_decode(\'&#x\'.$matches[1].\';\', ENT_NOQUOTES, \'UTF-8\');'), $str);
	}
}

Then to use it

$text = 'Welcome to my website.';
$trans_text = Google_Translate_API::translate($text, '', 'it');
if ($trans_text !== false) {
	echo $trans_text;
}

However it is limited on how much data you can input. Not to say how many translation requests you can …

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

This is a quote from my website

On an advanced content management system, you may want to offer a feature to convert text into different languages. Well I have created a script which uses the google translator to translate your data and send the translation to your website. So first copy the below function into the header of your php file.

function translate($sentence,$languagefrom,$languageto)
{
$homepage = file_get_contents('http://translate.google.com/translate_t');
if ($homepage==false) {$homepage='';}
preg_match_all("/<form[^>]+ction=\"\/translate_t\".*<\/form>/",$homepage,$botmatch);
$botmatch[0][0]=preg_replace("/<\/form>.*/",'',$botmatch[0][0]);
preg_match_all("/<input[^>]+>/",$botmatch[0][0],$botinput);
$id=0;
while (isset($botinput[0][$id]))
	{
	preg_match_all("/value=(\"|'|[^\"'])[^\"']+(\"|'|[^\"'])?( |>|	)/",$botinput[0][$id],$tmp);
	$tmp[0][0]=preg_replace('/((\'|")?[^\'"]+)/','$1',$tmp[0][0]);
	$tmp[0][0]=preg_replace('/(\'|")/','',$tmp[0][0]);
	$tmp[0][0]=preg_replace('/.*value=/i','',$tmp[0][0]);
	$len=strlen($tmp[0][0]);
	$len-=1;
	$tmp[0][0]=substr($tmp[0][0],0,$len);
 
	preg_match_all("/name=(\"|'|[^\"'])[^\"']+(\"|'|[^\"'])?( |>|	)/",$botinput[0][$id],$tmpname);
	$tmpname[0][0]=preg_replace('/((\'|")?[^\'"]+)/','$1',$tmpname[0][0]);
	$tmpname[0][0]=preg_replace('/(\'|")/','',$tmpname[0][0]);
	$tmpname[0][0]=preg_replace('/.*name=/i','',$tmpname[0][0]);
	$len=strlen($tmpname[0][0]);
	$len-=1;
	$tmpname[0][0]=substr($tmpname[0][0],0,$len);
 
	if (strlen($tmpname[0][0])>0 && !in_array($tmpname[0][0],array('text','sl','tl')))
		{
		$vars.=$tmpname[0][0]."=".$tmp[0][0].'&';
		}
	unset($tmp);
	unset($tmpname);
	$id+=1;
}
$curl_handle=curl_init('http://translate.google.com/translate_t');
curl_setopt($curl_handle, CURLOPT_HEADER, true);
curl_setopt($curl_handle, CURLOPT_FAILONERROR, true);
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, 
Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") );   
curl_setopt($curl_handle, CURLOPT_POST, true);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $vars.'text='.$sentence.'&sl='.$languagefrom.'&tl='.$languageto);
curl_setopt($curl_handle, CURLOPT_NOBODY, false);
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,false);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
 
$buffer=strip_tags($buffer,'<div>');
preg_match_all("/\<div id\=result_box dir\=\"[^\"]+\"\>[^<]+\<\/div\>/",$buffer,$match);
$match[0][0]=strip_tags($match[0][0]);
return $match[0][0];
}

Then to use the translator, you call the function like below and below is an example of english to chinese:

echo translate('This is the text','en','zh-CN');

The first field in the above function is the text to convert, second field language from, third field is language to. All languages are abbrievated. So below are the abbrievations you may use and that is it. It is as simple as that.

ar = Arabic
bg = Bulgarian
ca = Catalan
zh-CN = Chinese
hr = Croatian
cs = Czech
da = Danish
nl = Dutch
en = English
tl = Filipino
fi = Finnish …
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Your post is a bit unclear on which picture you want the result to look like. If you want the result as a table then that can be achieved by a simple while loop and a html table. If however you are trying to generate an image with the circles then I would suggest looking at the gd library.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Try making this line 58 and 59

$qry='SELECT * FROM employee WHERE username="'.mysql_real_escape_string($login).'" AND passwd="'.mysql_real_escape_string(md5($_POST['password'])).'"';
$result=mysql_query($qry) or die(mysql_error());

I have added some debugging functions which should help resolve the error.