link.php?target=[url]

Posted by: Gremelin

link.php?target=[url] - 02/10/04 01:02 PM

I have a perl script that I've been using since I got UGN Security started that will take and allow users to go to a URL (such as: link.cgi?target=http://www.undergroundnews.com/) and it'll load the page for them as if they just clicked the site, however it'll insert into a flat file the time they went to the site, their IP, and the site URL; it'll also increase the site's "popularity" in the flat file for each ckick. The script however isn't being worked on any further since the author's abandoned it due to it being a buggy piece of crap...

Now, what I want to do is take and have a similar URL string (like: link.php?target=http://www.undergroundnews.com/) that will take and enter the URL to the SQL database if it is new and follow the procedure for adding hits, if it's old it takes and adds a "hit" to the URL's stats in the SQL db and add's their IP/Time/URL to the db...

I'm not entirely sure how to go about it, I just know that I have to get it done ASAP due to this script bringing me more trouble than it's worth; but I have no clue how to begin; any Ideas? All help is appreciated, kudos goes to those who do the work for me (hey, I'm a busy fscking person)...
Posted by: §intå×

Re: link.php?target=[url] - 02/13/04 04:57 AM

You need 2 tables as I see it.

Database_hit_count
Code:
table 1
  URL    varchar (255)
  hits   int (11)
  last_hit_time varchar (15)
  id     int (11) auto increment key id uniqu
/tabel1
Code:
table2
  ip varchar (20)
  time varchar (15)
  bowser varchar (100)
  reffer varchar (150)
  id int(11) auto increment key id, uniqu
/table2
/Database_hit_count

$ip = "$REMOTE_ADDR"; //Grabs IP addy(built in variable in PHP)
$browser = "$HTTP_USER_AGENT"; //grabs browser info(built in to PHP)
$refferer = "$HTTP_USER_AGENT"; //dosen't allways work, but grabs refferer info (built into PHP)

The form tag could use the GET method to another page like I did in the RRFN. RRFN.php action attribute sends you to Database.php?keyword=What_you_searched_for

Soooooo

(form action="other_page.php" method="GET")
(!--some form stuff--)
(/form)

Code:
(?php

$ip = "$REMOTE_ADDR";  
$browser = "$HTTP_USER_AGENT";  
$refferer = "$HTTP_USER_AGENT";  
$URL = "$What_ever_you_named_it";
$this_date = date(see url for format options n/function.date.php);



//MYSQL_login crap here



$dg = mysql_query(SELECT * FROM table1 where URL = '$URL');
   $num_rows = mysql_num_rows($dg);
     if ($num_rows < 1){
        $dh = mysql_query("Insert into table1(feild names here)values(variable names here)");
         // repeate above for table 2
     }else{
         While ($dg2 = mysql_fetch_array($dg)){
             get count from table 1
             now $count = $count++;
             do an Update set feild name = '$variable'
}
That is rough, but that is basicaly how I would do it.
Posted by: Gremelin

Re: link.php?target=[url] - 02/13/04 06:59 AM

It's going to be for out of hosting sites; for linking to other sites basically.. I don't see anything in your code that'd resemble a function for calling url
Posted by: Gremelin

Re: link.php?target=[url] - 02/13/04 07:31 AM

Welp, scallion gave some input... Still thinkin of how to go about it lol...

Code:
Scallion: .
Scallion: you're unclear as to what you want
Gizmo: how so?
Gizmo: lol
Gizmo: i said
Gizmo: i want a script that
Gizmo: if you enter script.php?url=siteurl
Gizmo: it'll log the site url in a mysql db
Gizmo: if it's new
Gizmo: and if it exists it'll append a count to the db sayin how many times it's been accessed
Scallion: oh that's easy
Gizmo: does the post make sense now?
Gizmo: heh
Scallion: yeah a little more
Scallion: you should be able to do that on your own ;-)
Gizmo: :/
Scallion: do it like this
Scallion: redirect.php?url=xyz.com
Scallion: have a database like this:
Scallion: CREATE TABLE urls (url TEXT, num INT, id [int not null primary key blah blah blah])
Scallion: then in redirect.php, just access that table, if a select * from urls where url=$_GET[url] returns 0 rows, create a new row
Scallion: simple :-)
Gizmo: hos to have it append a numer to the amount of times it's been accesed?
Gizmo: better yet, what code to use to send user to site heh
Scallion: oh well put <?php header("Location: url"); ?> at the top of the page to redirect
Scallion: to append the num of times accessed, update a row with the url to add one to 'num' in the table.
Scallion: or use javascript to redirect.
Gizmo: mmmk
Posted by: §intå×

Re: link.php?target=[url] - 02/14/04 04:33 AM

$HTTP_REFERER sorry
Posted by: §intå×

Re: link.php?target=[url] - 02/14/04 04:34 AM

$_SERVER['PHP_SELF'] short path to script
Posted by: §intå×

Re: link.php?target=[url] - 02/14/04 04:43 AM

The only issue with scallions way is you will probably have sub scripts later.. Waht I mean is this

Code:
if(!$cmd){
//code executed when you first hit page
}
else if($cmd == "redirect_after_selection"){
//code to execute once user clicks said such link
}
so you links would be like so

replace ( with < and you get the idea

Code:
(a href="url_to_script/script.php?cmd=redirect&redirect=some_url.com" target="_self")
text or image link here
(/a)
Quick question, if you do not have the URL in your database.... Where will the user get it from? Or are you going to have all URLs re-routed through this..
Posted by: Gremelin

Re: link.php?target=[url] - 02/14/04 06:00 AM

I'm going to be linking to them. Go look at the links page; I like directly to all links i want in; i want it so i can just plug them in and have them go
Posted by: ninjaneo

Re: link.php?target=[url] - 02/16/04 01:15 PM

Code:
<?
 $db = mysql_connect("server","username","password");
 mysql_select_db("db");
 $updated = mysql_query("UPDATE `links` SET `hits`=`hits+1;");
 if(!$updated) {
  mysql_query("INSERT INTO `links` (`hits`,`url`) VALUES ('1','".$HTTP_GET_VARS["target"]."')");
 }
 mysql_close();
 header("Location: " . $HTTP_GET_VARS["target"]);
?>
That is one way to go about things... but that doesn't do hits so.. scrap that here. use the following.

link.php
Code:
 $db = mysql_connect("server","username","password");
 mysql_select_db("db");
 mysql_query("INSERT INTO `links` (`url`,`ip`,`time`,`referer`,`browser`) VALUES ('".addslashes($HTTP_GET_VARS["target"])."', '".$_SERVER["REMOTE_ADDR"]."', '".time()."', '".$HTTP_REFERER."', '".$HTTP_USER_AGENT."')");
 }
 mysql_close();
 header("Location: " . $HTTP_GET_VARS["target"]);
?>
viewhits.php
Code:
 $db = mysql_connect("server","username","password");
 mysql_select_db("db");
 $hits = mysql_query("SELECT `url` FROM `hits` GROUP BY `url`");
 echo("UGN linked to: ".mysql_num_rows($hits)." different web site(s).
\n");
 while($hit = mysql_fetch_array($hits)) {
  $url = mysql_query("SELECT * FROM `hits` WHERE `url`='".$hits["url"]."'");
  while($page = mysql_fetch_array($url)) {
   echo("url: ".$page["url"].", was visited by: ".$page["ip"].", at: ".date("h:i.a m/j/Y", $page["time"]).", using: ".$page["browser"]."; they came from: ".$page["referer"].".
\n");
  }
 }
 mysql_close();
?>
heres a mysql table for you...

Code:
CREATE TABLE `hits` (
`url` TEXT NOT NULL ,
`ip` VARCHAR( 15 ) NOT NULL ,
`time` INT UNSIGNED NOT NULL ,
`referer` TEXT NOT NULL ,
`browser` TEXT NOT NULL ,
FULLTEXT (
`url` ,
`referer` ,
`browser` 
)
) TYPE = MYISAM COMMENT = 'some hittage';
uhh, Talk to me if you wanan figure out how to do shit like... Tell how many people are using Mozilla Firebird or something.
Posted by: Gremelin

Re: link.php?target=[url] - 02/16/04 08:20 PM

Neo, on viewhits.php I get:
Quote:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\program files\easyphp\www\view.php on line 5
UGN linked to: different web site(s).

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\program files\easyphp\www\view.php on line 6
Posted by: Gremelin

Re: link.php?target=[url] - 02/16/04 08:21 PM

The code I'm using is:

Code:
<?php
 $db = mysql_connect("127.0.0.1","mysqluser","mysqlpass");
 mysql_select_db("ugn_linked");
 $hits = mysql_query("SELECT `url` FROM `hits` GROUP BY `url`");
 echo("UGN linked to: ".mysql_num_rows($hits)." different web site(s).
\n");
 while($hit = mysql_fetch_array($hits)) {
  $url = mysql_query("SELECT * FROM `hits` WHERE `url`='".$hits["url"]."'");
  while($page = mysql_fetch_array($url)) {
   echo("url: ".$page["url"].", was visited by: ".$page["ip"].", at: ".date("h:i.a m/j/Y", $page["time"]).", using: ".$page["browser"]."; they came from: ".$page["referer"].".
\n");
  }
 }
 mysql_close();
?>
Posted by: §intå×

Re: link.php?target=[url] - 02/18/04 10:01 AM

Code:
$hits = mysql_query("SELECT `url` FROM `hits` GROUP BY `url`");
most likely it is this line causeing your error on line 5.


your table name isn't something like undergroundnews_hits is it? If so you need to

Code:
 $hits = mysql_query("SELECT `url` FROM `undergroundnews_hits` GROUP BY `url`");
use something like the above. If you have php My Admin it will tell you the full table name. if you want to use telnet, or ssh or command line


http://www.undergroundnews.com/cgi-bin/ubbcgi/ultimatebb.cgi?/topic/9/81.html

Might want to try your query in ther to test it before you run the script just to prove it out.
Posted by: Gremelin

Re: link.php?target=[url] - 02/18/04 01:18 PM

Ok, a new issue now...

view.php
Quote:

http://www.undergroundnews.org/ 127.0.0.1 1077110092
http://www.undergroundnews.net/ 127.0.0.1 1077110084
http://www.undergroundnews.com/ 127.0.0.1 1077110059
And in view.php I get the output of:
Quote:

UGN linked to: 3 different web site(s).
I need it to at least tally how many times it went to each site...