need help spliting this code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
volkan
Forum Commoner
Posts: 60
Joined: Sat Aug 21, 2004 1:12 pm
Location: London, United Kingdom

need help spliting this code

Post by volkan »

Hi
I found this code:

Code: Select all

<?php
	/*

		SQL Dump:

		CREATE TABLE `hits` (
		  `id` smallint(8) NOT NULL default '0',
		  `ip` varchar(15) NOT NULL default '',
		  `time` varchar(20) NOT NULL default ''
		) TYPE=MyISAM;

		CREATE TABLE `uhits` (
		  `id` int(8) NOT NULL default '0',
		  `ip` varchar(15) NOT NULL default '',
		  `time` varchar(15) NOT NULL default '',
		  KEY `id` (`id`)
		) TYPE=MyISAM;
	*/


	// Configuration
	$sql_host = "localhost";   // MySQL host
	$sql_user = "root";        // MySQL username
	$sql_pass = "my_pass";  // MySQL password
	$sql_data = "my_database";   // MySQL database


/////////////////////////////////////////////////////////////////////////

	// Setting the time and IP into variables
	$time = date("mdY");
	$ip = $_SERVER['REMOTE_ADDR'];

	// Connection to the mysql database...
	$sql_c = mysql_connect("$sql_host", "$sql_user", "$sql_pass") or die("MySQL Error:\n".mysql_error()."");

	// Selecting the mysql database...
	mysql_select_db("$sql_data") or die("MySQL Error: ".mysql_error()."");

	// Getting and updating "all hits"
	$j_hits = mysql_query("SELECT * FROM `hits`") or die("MySQL Error:\n ".mysql_error()."");
	if (mysql_num_rows($j_hits) <= 0) { $hits = "1"; } else { $hits = mysql_num_rows($j_hits)+1; }
	mysql_query("INSERT INTO `hits` (ip,time) VALUES ('$ip','$time')") or die("MySQL Error:\n".mysql_error()."");

	// Getting today's hits
	$t_hits = mysql_query("SELECT * FROM `hits` WHERE `time` = '$time'") or die("MySQL Error:\n".mysql_error()."");
	if (mysql_num_rows($t_hits) <= 0) { $thits = "1"; } else { $thits = mysql_num_rows($t_hits); }

	// Getting and updating "all unique hits"
	$u_hits = mysql_query("SELECT * FROM uhits") or die("MySQL Error:\n ".mysql_error()."");
	if (mysql_num_rows($u_hits) <= 0) { $uhits = "1"; } else { $uhits = mysql_num_rows($u_hits); }
	$ips = mysql_query("SELECT * FROM `uhits` WHERE ip = '$ip'") or die("MySQL Error:\n ".mysql_error()."");
	if (mysql_num_rows($ips) <= 0) { mysql_query("INSERT INTO `uhits` (ip,time) VALUES ('$ip', '$time')") or die("MySQL Error:\n".mysql_error().""); }

	// Getting unique hits for today
	$ut_hits = mysql_query("SELECT * FROM uhits WHERE `time` = '$time'") or die("MySQL Error:\n ".mysql_error()."");
	if (mysql_num_rows($ut_hits) <= 0) { $uthits = "1"; } else { $uthits = mysql_num_rows($ut_hits); }

	// Closing connection to MySQL
	if ($sql_c) { mysql_close($sql_c); }

	// Printing out results
	echo ("
		Hits $hits <br />\n
		Today $thits <br />\n
		Unique $uhits <br />\n
		Unique today $uthits <br />\n
	");
?>
And edited it to:

Code: Select all

<?php
	/*
	
		SQL Dump:

		CREATE TABLE `hits` (
		  `id` smallint(8) NOT NULL default '0',
		  `ip` varchar(15) NOT NULL default '',
		  `time` varchar(20) NOT NULL default ''
		) TYPE=MyISAM;

	*/


	// Configuration
	$sql_host = "*********";   // MySQL host
	$sql_user = "********";        // MySQL username
	$sql_pass = "*******";  // MySQL password
	$sql_data = "******";   // MySQL database


////////////////////////////////////////////////////////////////////////////

	// Setting the time and IP into variables
	$time = date("mdY");
	$ip = $_SERVER['REMOTE_ADDR'];

	// Connection to the mysql database...
	$sql_c = mysql_connect("$sql_host", "$sql_user", "$sql_pass") or die("MySQL Error:\n".mysql_error()."");

	// Selecting the mysql database...
	mysql_select_db("$sql_data") or die("MySQL Error: ".mysql_error()."");

	// Getting and updating "all hits"
	$j_es = mysql_query("SELECT * FROM `es`") or die("MySQL Error:\n ".mysql_error()."");
	
	if (mysql_num_rows($j_es) <= 0) { $es = "1"; } else { $es = mysql_num_rows($j_es)+1; }
	
	mysql_query("INSERT INTO `es` (ip,time) VALUES ('$ip','$time')") or die("MySQL Error:\n".mysql_error()."");


	// Closing connection to MySQL
	if ($sql_c) { mysql_close($sql_c); }

	// Printing out results
	echo ("
		Hits $es <br />\n

	");
?>
Which fully works,
Then I tried to split it up,
Thats when I ran into problems,
http://www.rc-expertise.com/build.php (See Graupner HotSpot )
Im trying to show the hits on build.php
while insert the hits into a DB via a
differant server (wrap.php?url=http://vk1.blogdns.com/build/hs)

Here is how I split it up:

build.php (in the table)

Code: Select all

<?php
	$sql_host = "*********";   // MySQL host
	$sql_user = "********";        // MySQL username
	$sql_pass = "*******";  // MySQL password
	$sql_data = "******";   // MySQL database
?>



      <?php
		$sql_c = mysql_connect("$sql_host", "$sql_user", "$sql_pass") or die("MySQL Error:\n".mysql_error()."");

	// Selecting the mysql database...
	mysql_select_db("$sql_data") or die("MySQL Error: ".mysql_error()."");
	
	$j_hs = mysql_query("SELECT * FROM `hs`") or die("MySQL Error:\n ".mysql_error()."");
	
	if (mysql_num_rows($j_hs) <= 0) { $es = "1"; } else { $hs = mysql_num_rows($j_hs)+1; }
	echo ("	Hits: $hs ");
	?>


And on index.php on the other server
I have:

Code: Select all

<?php
	$sql_host = "*********";   // MySQL host
	$sql_user = "********";        // MySQL username
	$sql_pass = "*******";  // MySQL password
	$sql_data = "******";   // MySQL database
?>


<?php
	// Setting the time and IP into variables
	$time = date("mdY");
	$ip = $_SERVER['REMOTE_ADDR'];

	// Connection to the mysql database...
	$sql_c = mysql_connect("$sql_host", "$sql_user", "$sql_pass") or die("MySQL Error:\n".mysql_error()."");

	// Selecting the mysql database...
	mysql_select_db("$sql_data") or die("MySQL Error: ".mysql_error()."");

	// Getting and updating "all hits"
	$j_es = mysql_query("SELECT * FROM `es`") or die("MySQL Error:\n ".mysql_error()."");
	
	if (mysql_num_rows($j_es) <= 0) { $es = "1"; } else { $es = mysql_num_rows($j_es)+1; }
	
	mysql_query("INSERT INTO `es` (ip,time) VALUES ('$ip','$time')") or die("MySQL Error:\n".mysql_error()."");


	// Closing connection to MySQL
	if ($sql_c) { mysql_close($sql_c); }

	// Printing out results
	echo ("
		Hits $es <br />\n

	");
	?>
I have two Problems.
ONE
on http://www.rc-expertise.com/wrap.php?ur ... m/build/hs
I get:

Code: Select all

Warning: mysql_connect(): Client does not support authentication protocol requested by server; consider upgrading MySQL client in /var/www/vk1/build/hs/index.php on line 335
MySQL Error: Client does not support authentication protocol requested by server; consider upgrading MySQL client
What does that mean.

TWO
I but index.php (from the other server) onto
the same server, and the counter works fine....
http://www.rc-expertise.com/build/index.php (bottom of the page)
But now, on http://www.rc-expertise.com/build.php It isnt collecting the
info from the DB.

This is driven me mad!!
Please help me!!!!
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

the first problem arises if the mysql db is updated to >4.1..
solution can be easily found in the mysql manual and in the posts on this forum... just use "Client does not support authentication protocol requested by server" as keywords...

btw, consider an appropriate type for storing a datetime/timestamp instead of varchar... will save you from serious headaches later..
User avatar
volkan
Forum Commoner
Posts: 60
Joined: Sat Aug 21, 2004 1:12 pm
Location: London, United Kingdom

Post by volkan »

I acctulley dont really need the date an time!
All i need is the hits counter, which I cant get working.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

try this you should:

Code: Select all

mysql>set password for yourusername@yourhost = old_password('yourpassword');
User avatar
volkan
Forum Commoner
Posts: 60
Joined: Sat Aug 21, 2004 1:12 pm
Location: London, United Kingdom

Post by volkan »

Why would I need that?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

if you dont stfw/rtfm you'll never know...
User avatar
volkan
Forum Commoner
Posts: 60
Joined: Sat Aug 21, 2004 1:12 pm
Location: London, United Kingdom

Post by volkan »

timvw wrote:if you dont stfw/rtfm you'll never know...
I will do.
BUT
i need to fix my SECOND problem, then I could
fix the FIRST
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

at first sight you are using table hs in build.php

and table es in index.php. why?
User avatar
volkan
Forum Commoner
Posts: 60
Joined: Sat Aug 21, 2004 1:12 pm
Location: London, United Kingdom

Post by volkan »

Im trying to split the code between index.php and
build.php

So, when someone goes on index.php, the hits will show on build.php
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

but why are you writing to table "es" and reading from table "hs"

this way, it will always look like nothing has changed... because you changed a different table
User avatar
volkan
Forum Commoner
Posts: 60
Joined: Sat Aug 21, 2004 1:12 pm
Location: London, United Kingdom

Post by volkan »

LOL!
Thats why!!!!!

Now, for the other problem,
I dont have access to the mysql
ini files or cmd.

Only PHPmyAdmin
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

well now is the time to search for " MySQL Reference Manual :: A.2.3 Client does not support authentication protocol"

or just look at burrito's post and run that command... if i'm not mistaken you can also send custom commands with phpmyadmin (under the sql tab)
Post Reply