Jump to content

Recommended Posts

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
Link to comment
https://forums.phpfreaks.com/topic/13827-click-counter/
Share on other sites

Modify to your needs
[code]                <?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);
                }
?>[/code]

Datebase:
[quote]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`)
)[/quote]

If you need more explainations feel free to ask.
Link to comment
https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-53763
Share on other sites

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

[table][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);
                }
?>[/table]

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


Link to comment
https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-53799
Share on other sites

-_-! 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 [b]http://domain/index.php?file=1[/b] 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
Link to comment
https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-53819
Share on other sites

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
Link to comment
https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-54237
Share on other sites

[code]<?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.";
            }
  }
?>[/code]

[b][color=red]Note[/color][/b]: 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
Link to comment
https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-54244
Share on other sites

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
Link to comment
https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-54257
Share on other sites

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

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

Remeber to change the config.
Link to comment
https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-54259
Share on other sites

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/hitcounter/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
Link to comment
https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-54264
Share on other sites

I assume your click.php contains:
[code]<?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);
                }
            ?>[/code]

Go to line 6 and remove [b]<?php[/b]
Link to comment
https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-54267
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-54293
Share on other sites

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?
Link to comment
https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-54370
Share on other sites

This forum is the best forum ive seen, with the most helpful experts around,

not to mention : hackerkts

I couldnt have been taken care of any better any where else,

fast response, easy solutions, and dedicated customer service.

unbeatable...............

and one extrememly happy webdeveloper ;D
Link to comment
https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-54698
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.