Jump to content


Photo

Click Counter


  • Please log in to reply
22 replies to this topic

#1 danlew

danlew
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts

Posted 06 July 2006 - 09:00 AM

My first time here & I am trying to develop a click counter that counts individual customers websites hit and leaves a count next to there click website icon,

I ONLY KNOW THE BASICS OF PHP & MYSQL and i have created some PHP files & a MYSQL database which i have not yet completed the MYSQL database will be INT or BIGINT to store millions of numerical values. ( I Believe )

I would like when anybody hits this link for example - www.mywebsite/hit/click.php?id=1 it will go to address www.mycustomer.com

than i will need to have a databse to store the website addresses or id no's?

for example www.mywebsite/hit/click.php?id=1 - www.mycustomer.com
for example www.mywebsite/hit/click.php?id=2 - www.anothercustomer.com

how do iset the database to enter this???

also....

in PHP i have designed about 7 files all hopefully communicating with mysql the way its meant to? i can also show you these files if i run into troubles which im more than likely going to.

and than lastly.....

i will have the html files that contain the websites of my customers, with an click icon, when they click on the icon it will read just next to it the no. of times its been hit.

the way ive done that is put the click button link to address: ww.mywebsite/hit/click.php?id=1 for example than it gets redirected to the website www.mycustomer.com and no of clicks also gets stored either in a txt.file ar database in which i assume is most likely the case.

Hope this all makes sense, and have some body help me with this,

thanks very much

#2 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 06 July 2006 - 09:38 AM

Modify to your needs
                <?php
                if(!empty($_GET['file'])) {
                $id = $_GET['file'];
                function go_to_file($id)
                {
                    $dl_query = "SELECT * from counter WHERE id ='$id'";
                	$dl_result = mysql_query($dl_query) or die("Query failed: " . mysql_error());
                	$dl_row = mysql_fetch_array($dl_result);
                    $id = $dl_row['id'];
					$FileName = $dl_row['FileName'];
					$FileURL = $dl_row['FileURL'];
					$Count = $dl_row['Count'];
                	$go = "<META HTTP-EQUIV='refresh' CONTENT='0;URL=". $FileURL ."'>";
                    $dl_query = "UPDATE counter SET Count=Count+1 WHERE id='$id'";
                	$dl_result = mysql_query($dl_query) or die("Query failed: " . mysql_error());
                    return $go;
                }
                echo go_to_file($id);
                }
				?>

Datebase:

CREATE TABLE `counter` (
  `id` int(5) NOT NULL auto_increment,
  `FileName` varchar(50) NOT NULL,
  `FileURL` varchar(255) NOT NULL,
  `Count` int(5) NOT NULL,
  PRIMARY KEY  (`id`)
)


If you need more explainations feel free to ask.

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#3 danlew

danlew
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts

Posted 06 July 2006 - 11:28 AM

WOW! So this all seems easier than what i thought,

does this mean its just simply 1 php file (index.php) i have the following

[tr][td]<?php
mysql_connect("<MYHOSTNAME", "USER","PASSWORD") or die(mysql_error());
mysql_select_db("COUNTER") or die(mysql_error());
$data = mysql_query("SELECT * FROM friends")
or die(mysql_error());
<?php
if(!empty($_GET['file'])) {
                $id = $_GET['file'];
                function go_to_file($id)
                {
                    $dl_query = "SELECT * from counter WHERE id ='$id'";
                $dl_result = mysql_query($dl_query) or die("Query failed: " . mysql_error());
                $dl_row = mysql_fetch_array($dl_result);
                    $id = $dl_row['id'];
$FileName = $dl_row['FileName'];
$FileURL = $dl_row['FileURL'];
$Count = $dl_row['Count'];
                $go = "<META HTTP-EQUIV='refresh' CONTENT='0;URL=". $FileURL ."'>";
                    $dl_query = "UPDATE counter SET Count=Count+1 WHERE id='$id'";
                $dl_result = mysql_query($dl_query) or die("Query failed: " . mysql_error());
                    return $go;
                }
                echo go_to_file($id);
                }
?>


AND WITH MYSQL

when i insert what would go in the following?
ID: 1 etc.
FILE NAME: books.html
FILE URL: www.clientswebsite.com or www.mywebsite.com/click/id1.php

AND WITH MY WEBPAGES

WHERE IN MY WEBPAGES DO I ENTER A SCRIPT FOR IT TO READ THE DATABASE AND PHP FILE




#4 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 06 July 2006 - 12:11 PM

-_-! You last 2 lines should use capital letters.

ID you just ignore them, it will auto increase by 1, File name is actually the Site name and the FileURL is actually the page url.

It depends where you want this script to work,
ok let's say if you save it as index.php

Then you can access it by going to http://domain/index.php?file=1 It will redirects you to your FileURL index 1.

P.S: I think you should change the $_GET['file'] to $_GET['page'] so it will be page=1 instead of file=1

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#5 danlew

danlew
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts

Posted 07 July 2006 - 05:30 AM

Great, so is this how it would be when i go to insert in mYSQL?
for example?

File URL: www.mywebsite.com
File Name: www.customerswebsite.com

File URL: www.mywebsite.com
File Name: www.anothercustomerswebsite.com

Is this right?

and.......

Is it possible to have another php file to add data to for it to get stored into MYSQL? so i dont have to enter in MYSQL, and what is the best way to code the other php file. than i just enter data as a webform do i? for example www.mywebsite/adddata.php.

Thanks very much

#6 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 07 July 2006 - 06:13 AM

<?php
if (!isset($_POST['submit'])) {
?>
   <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <div>
      Page Name: <input type="text" name="name" style="width:120px; height:18px; font-family:Tahoma; font-size:11px "><br>
      Page URL:&nbsp;&nbsp; <input type="text" name="url" style="width:120px; height:18px; font-family:Tahoma; font-size:11px ">
      <input type="submit" name="submit" value="Submit">
    </div>
   </form>
<?php
} else {
	$name = $_POST['name'];
    $url = $_POST['url'];
    if ($name == "" || $url == "") {
    	echo "Please fill up all the blanks.";
        } else {
        	mysql_query("INSERT INTO `counter` VALUES ('', '$name', '$url', '0')") or die ("There's some problem inserting the informations.");
            echo "You have successfully insert the informations.";
            }
  }
?>

Note: If you just use the scripts above, anyone can enter the informations into database. You need to modify alittle more to ensure only user with permission can enter it.  :D

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#7 danlew

danlew
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts

Posted 07 July 2006 - 07:08 AM

I just named the file adddata.php and just edited the top as follows;

<?php
if (!isset($_POST['submit'])) {
?>
  <FORM name=senddata action=./adddata.php method=post>
    <div>
      Page Name: <input type="text" name="name" style="width:120px; height:18px; font-family:Tahoma; font-size:11px "><br>
      Page URL: <input type="text" name="url" style="width:120px; height:18px; font-family:Tahoma; font-size:11px ">
      <input type="submit" name="submit" value="Submit">
    </div>
  </form>
<?php
} else {
$name = $_POST['name'];
    $url = $_POST['url'];
    if ($name == "" || $url == "") {
    echo "Please fill up all the blanks.";
        } else {
        mysql_query("INSERT INTO `counter` VALUES ('', '$name', '$url', '0')") or die ("There's some problem inserting the informations.");
            echo "You have successfully insert the informations.";
            }
  }
?>


BUT!!!!!

It gives me a error like this;

mysql_query(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /home/content/t/h/a/website/html/hitcounter/adddata.php on line 18

#8 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 07 July 2006 - 07:16 AM

Lolz :P
I fogotten to tells you to add connection to your MySQL.

Add this below <?
$host = "localhost";
$username = "root";
$password = "";
$db = "database";
mysql_connect($host,$username,$password) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());

Remeber to change the config.

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#9 danlew

danlew
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts

Posted 07 July 2006 - 07:57 AM

Ok, The adddata form seems to work now, i would also like the option of find / switch to edit - id

also.......

i just did a test

from one of my webpages to click on http://www.mywebsite.../click.php?id=1

and it gave me error

Parse error: parse error, unexpected '<' in /home/content/t/h/a/mywebsite/html/hitcounter/click.php on line 6


#10 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 07 July 2006 - 08:05 AM

I assume your click.php contains:
<?php
mysql_connect("<MYHOSTNAME", "USER","PASSWORD") or die(mysql_error());
mysql_select_db("COUNTER") or die(mysql_error());
$data = mysql_query("SELECT * FROM friends")
or die(mysql_error());
<?php
if(!empty($_GET['file'])) {
                $id = $_GET['file'];
                function go_to_file($id)
                {
                    $dl_query = "SELECT * from counter WHERE id ='$id'";
                   $dl_result = mysql_query($dl_query) or die("Query failed: " . mysql_error());
                   $dl_row = mysql_fetch_array($dl_result);
                    $id = $dl_row['id'];
               $FileName = $dl_row['FileName'];
               $FileURL = $dl_row['FileURL'];
               $Count = $dl_row['Count'];
                   $go = "<META HTTP-EQUIV='refresh' CONTENT='0;URL=". $FileURL ."'>";
                    $dl_query = "UPDATE counter SET Count=Count+1 WHERE id='$id'";
                   $dl_result = mysql_query($dl_query) or die("Query failed: " . mysql_error());
                    return $go;
                }
                echo go_to_file($id);
                }
            ?>

Go to line 6 and remove <?php


Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#11 danlew

danlew
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts

Posted 07 July 2006 - 08:11 AM

we are nearlly there..... i think :P

silly me i had removed line 6 ( <?php )

now i get a different error message when i click and test the link....

Table 'backtobasics.friends' doesn't exist


#12 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 07 July 2006 - 08:32 AM

Sorry for the late reply, was writing a script for someone.

Hmm... Check your database, you don't have the table friends

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#13 danlew

danlew
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts

Posted 07 July 2006 - 08:38 AM

I accidently copied this line from another php scrip i had

$data = mysql_query("SELECT * FROM friends")

can i just delete friends, i dont have a table called friends? and what do i replace the "friends with?

#14 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 07 July 2006 - 08:41 AM

Remove
$data = mysql_query("SELECT * FROM friends")
or die(mysql_error());


Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#15 danlew

danlew
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts

Posted 07 July 2006 - 08:52 AM

I have now removed that,

than when i click the link to go to http://www.mywebpage.../click.php?id=1

it just gives me a blank page

#16 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 07 July 2006 - 08:56 AM

Have you put something into database ?

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#17 danlew

danlew
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts

Posted 07 July 2006 - 09:10 AM

Thankyou for your quick response/s,

Ok currently i am experiencing difficulty getting my php admin / mysql access page to load,

it keeps on timing out

i will hopefully sort this out and get back to you once this has resolved,

or in another case could be the reason as to why its showing blank.

#18 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 07 July 2006 - 09:19 AM

Don't worry about that, take your time. :P

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#19 danlew

danlew
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts

Posted 07 July 2006 - 01:26 PM

Ok, 5 hours later i resolved the php/mysql admin issue with my host,
Scarey stuff, huh, as well as back up all my other databases...
.......................................................................................

When i click on the link it now seems to be directing/going to the appropriate website url i allocate. wihich is great, (well done!)

but..

It doesnt show the hit count display (no. of times being clicked in simple text display ) next to the icon i click?

#20 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 07 July 2006 - 02:28 PM

Do you have a live demo ? I wanna see where you wanna put it at.

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users