xtjx09 Posted February 16, 2009 Share Posted February 16, 2009 I want to log the IP and the filename of every person who downloads something off my server. I want to log when i click the filename link to the file. To do that, i would have to use postvariables correct? Ive been looking into using a form with no submit button, but i have had no luck. This is something i would like to accomplish sooner rather than later, so a speedy response would be greatly appreciated. Here is the page... <?php session_start(); if(!isset($_SESSION['admin'])) { header('Location: index.php'); } else { $ip=@$REMOTE_ADDR; #connects to localhost with a username of root and a password of gooder mysql_connect("server", "user", "pass"); @mysql_select_db(db) or die("Unable to connect to database."); if (isset($_GET["id"])) { #sends the information about the file, filename, size, type, and where from of the file that is downloable $id=$_GET["id"]; $query="select filename, type, size, content from home where id = '$id'"; $result=mysql_query($query); list($filename, $type, $size, $content)=mysql_fetch_array($result); header("Content-length: $size"); header("Content-type: $type"); header("Content-Disposition: attachment; filename=$filename"); echo $content; exit; } if (isset($_POST['delete'])) { if (isset($_POST['del'])) { $dele = $_POST['del']; foreach ($dele as $value ) { $del = "DELETE FROM home WHERE id = $value"; $de = mysql_query($del); } $deleted= "Entry Deleted"; }else { echo "No data selected."; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html> <head> <title>[CKK]TJ Home</title> <link rel="stylesheet" type="text/css" href="css/screen.css" media="screen, print" /> </head> <body> <div id="header"> <div id="menu"> <ul> <li><a href="index.php" title="Home" class="active">Home</a></li> <li><a href="<?php echo "abyss.php" ?>" title="Downloads">Downloads</a></li> <li><a href="school.php" title="School">School</a></li> <li><a href="upload.php" title="upload" style="width: 8.7em;">Upload</a></li> <li><a href="logout.php" title="Logout" style="width: 7em;">Logout</a></li> </ul> <div id="title"> <h1>[CKK]<?php echo $_SESSION['user'] ?></h1> </div> </div> </div> <div id="content"> <div id="text"> <h1><span>[CKK]TJ</span></h1> <p > <?php #And if else statement that will be creating a table to display what is available $query="select id, uploader, filename, type, size from home ORDER BY id DESC"; $result=mysql_query($query); if (mysql_num_rows($result)==0) { echo "Database is Empty<br />"; } else { ?> <form method="post"> <table width= "1" "cellpadding= "0px" border="2" style= "text-align: center; margin: 0 auto;"> <tr> <th> Uploader </th> <th> FileName </th> <th>Delete</th> </tr> <?php #A while is created if there are items in the database to display information about the file that is downloadable while (list($id, $uploader, $filename, $type, $size)=mysql_fetch_array($result)) { ?> <tr> <td> <?php echo $uploader;?> </td> <td> <form name= "downloadme" method ="post" action="abyss.php?id=<?php echo $id;?>"> <td><?php echo $filename;?></td> <input type="hidden" name="downloadip" /> </form> </td> <td> <input type="checkbox" name="del[]" value="<?php echo $id ?>"> </td> </tr> <?php } ?> </form> </table> <span style= "text-align: center; margin: 0 auto; display: block; width: 250px;"> <a href= "more.php" style= "font-size: 12;"> More </a> <br /><br /><br /> <input type="submit" name="delete" value="Delete" style= "width: 100px;"/> <br/> <?php echo $deleted; ?> </span> <?php } ?> <span style= "text-align: center;"> </span> </p> </div> <div id="image"><img src="images/plants.jpg" alt="plants"/></div> <div id="sideBar"> <h1><span>Quotes</span></h1> <div id="comments"> <p> "You can discover what your enemy fears most by observing the means he uses to frighten you." <span class="author">Eric Hoffer</span> </p> <img src="images/comment_bg.gif" alt="comment bottom"/> <p> "The bravest are surely those who have the clearest vision of what is before them, glory and danger alike, and yet notwithstanding go out to meet it." <span class="author">Thucydides</span> </p> <img src="images/comment_bg.gif" alt="comment bottom"/> <p> "Anything I've ever done that ultimately was worthwhile... initially scared me to death." <span class="author">Betty Bender</span> </p> <img src="images/comment_bg.gif" alt="comment bottom"/> </div> <?php if(!isset($_SESSION['loggedin'])) { ?> <h1><span>Login</span></h1> <form method = "POST"> <p> <input type="text" name= "user" value="<?php echo $valueuser ?>" onfocus=" value=''"/> <input type="password" value="Password" name= "password" onfocus=" value=''"/> <input type="submit" value="Login" class="button" name= "submit"/> </p> <?php } else { ?> <h1><span>Logged in as <?php echo $_SESSION['user']; ?> </span></h1> <?php } ?> <?php echo $welcome; #echo $loggedin; echo $fail_login; echo $fields; echo $administrator; ?> </form> </div> <div id="footer"> <a href="http://fullahead.org" title="designed by fullahead.org" class="fullAhead"></a> <p>Valid <a href="http://validator.w3.org/check?uri=referer" title="validate XHTML">XHTML</a> & <a href="http://jigsaw.w3.org/css-validator" title="validate CSS">CSS</a></p> </div> </div> </body> <?php } ?> </html> Link to comment https://forums.phpfreaks.com/topic/145363-insert-ip-when-download-a-file/ Share on other sites More sharing options...
btherl Posted February 16, 2009 Share Posted February 16, 2009 You can use $_SERVER['REMOTE_ADDR'] instead of @$REMOTE_ADDR As for doing the recording, can you record it inside abyss.php? At that stage you know both which file is selected and what the user's IP address is. Link to comment https://forums.phpfreaks.com/topic/145363-insert-ip-when-download-a-file/#findComment-763099 Share on other sites More sharing options...
xtjx09 Posted February 16, 2009 Author Share Posted February 16, 2009 I planned on recording it then, my problem is that i only wanted to log the people who download, I wanted to insert the IP along with the Filename on the abyss.php page, but that would require a form right? i really dont wanna make a checkbox type download page. Link to comment https://forums.phpfreaks.com/topic/145363-insert-ip-when-download-a-file/#findComment-763621 Share on other sites More sharing options...
btherl Posted February 17, 2009 Share Posted February 17, 2009 A form doesn't necessarily mean checkbox or submit button. Google for "submit form with link" will give you plenty of examples. Is it just the appearance of the download link that you are concerned about? Link to comment https://forums.phpfreaks.com/topic/145363-insert-ip-when-download-a-file/#findComment-763863 Share on other sites More sharing options...
xtjx09 Posted February 18, 2009 Author Share Posted February 18, 2009 Everywhere is saying that i need a CGI? What is a CGI and is there a way around using one? Link to comment https://forums.phpfreaks.com/topic/145363-insert-ip-when-download-a-file/#findComment-765187 Share on other sites More sharing options...
btherl Posted February 19, 2009 Share Posted February 19, 2009 CGI? That's an old term. PHP scripts were called "CGI" a long time ago. http://en.wikipedia.org/wiki/Common_Gateway_Interface Link to comment https://forums.phpfreaks.com/topic/145363-insert-ip-when-download-a-file/#findComment-765711 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.