Jump to content

PHP Newbie needs help badly plz!


MistyEyes

Recommended Posts

Hello,

This is my 1st time here. I will say I know nothing about php!

I know I have it on my server.

 

What I am trying to do is log and ip of whom ever clicks on a certain picture.

I am using a nice, simple script. I get an error when trying to write the log.

Here is the part that is giving the error:

 

//here, we open the logfile for writing to. The 'a' means when we write

// data to the text file, it will be appended to the end of the file

$fh = fopen($logs, 'a') or die(" "); 

 

And this is the error, which is on line 18:

 

Warning: fopen(http://www.mysite.com/ip_log/logs.txt): failed to open stream: HTTP wrapper does not support writeable connections. in /home/me/mysite/picture.jpg/index.php on line 18

 

what do I need to do NOT to get that error?

 

Thank you so much, in advance!

 

Link to comment
Share on other sites

I changed it as you suggested, and received another error on another line.

I am going to post the raw script so you can see actually what I am working with.

 

 

<?php

// Ip recorder, use in the format yoursite.com/picture.jpg/index.php

//this picture variable defines which image to show the victim
$picture = "http://mysite.com/w/w060529_2.jpg";

//this line just gets the visitor's ip address and stores it in the variable '$ip'
$ip = $_SERVER['REMOTE_ADDR'];

//this line tells the logger the name you want to use for the log file.
// if the logfile doesn't already exist, it will be created automagically
$logs = "logs.txt";

//here, we open the logfile for writing to. The 'a' means when we write
// data to the text file, it will be appended to the end of the file
$fh = fopen($logs, 'a') or die(" ");

//here we put the ip address into a variable called 'string data'
// the backslash-n starts a new line in the text file, to make it easier to read
$stringData = "$ip \n";

//here we write to the text file what is in the stringdata variable
fwrite($fh, $stringData);

//now we close the file
fclose($fh);


//and finally we echo some html back to the user's browser so they see an image
echo "<img src='$picture'>";

?>

 

thanks again! :)

 

 

Link to comment
Share on other sites

Sorry for the delayed reply, but lots of thunder and lightning causes my adsl to stop, then go then stop ....

 

The error I now receive is:

 

Warning: fopen(/me/mysite/ip_logs/logs.txt): failed to open stream: No such file or directory in /home/me/my site/picture.jpg/index.php on line 19 

 

 

which is here -

//here, we open the logfile for writing to. The 'a' means when we write

// data to the text file, it will be appended to the end of the file

$fh = fopen($logs, 'a') or die(" ");

 

Link to comment
Share on other sites

This is nutz!

I had that dir, with the txt file there.

I changed the name from logs to log, and now I am getting yet another error :(

 

Warning: fopen(/home/me/mysite/ip_logs/log.txt): failed to open stream: Permission denied in /home/me/mysite/PHONEYPIC.jpg/index.php on line 18

 

Line 18 is:  $fh = fopen($logs, 'a') or die(" ");

Link to comment
Share on other sites

YIPEEEEEEEEE!

Now THAT last one made me feel 'tupid with a CAP  "T"

:(

I had it semi working before with the correct permissions, and when I changed the files,

I forgot to re-CHMOD the file.

 

(and it actually logged my ip)  :)

 

I want to thank every one that helped me with this!

You are all wonderful and you were VERY gentle with me!  ha ha ha!

Link to comment
Share on other sites

remember ... php noob here..LOL...

Is that a different kind of php script used to break the proxy to the real ip?

(I have to learn this!)

 

 

I will check back here later, as we are going to a 4th party.

 

BBL and thank you all again! :)

Link to comment
Share on other sites

<?php
//List of the private ips described in the RFC. You can easily add the 
//127.0.0.0/8 to this if you need it.

$ip_private_list=array(
                       "10.0.0.0/8",
                       "172.16.0.0/12",
                       "192.168.0.0/16"
);

//Determine if an ip is in a net.
//E.G. 120.120.120.120 in 120.120.0.0/16
//I saw this in another post in this site but don't remember where 

function isIPInNet($ip,$net,$mask) {
  $lnet=ip2long($net);
  $lip=ip2long($ip);
  $binnet=str_pad( decbin($lnet),32,"0","STR_PAD_LEFT" );
  $firstpart=substr($binnet,0,$mask);
  $binip=str_pad( decbin($lip),32,"0","STR_PAD_LEFT" );
  $firstip=substr($binip,0,$mask);
                                                                                
  return(strcmp($firstpart,$firstip)==0);
}

//This function check if a ip is in an array of nets (ip and mask)

function isIpInNetArray($theip,$thearray)
{
  $exit_c=false;
  #print_r($thearray);
  foreach ( $thearray as $subnet ) {
    list($net,$mask)=split("/",$subnet);
    if(isIPInNet($theip,$net,$mask)){
      $exit_c=true;
      break;
    }
  }
  return($exit_c);
}

//Building the ip array with the HTTP_X_FORWARDED_FOR and 
//REMOTE_ADDR HTTP vars.
//With this function we get an array where first are the ip's listed in 
//HTTP_X_FORWARDED_FOR and the last ip is the REMOTE_ADDR.
//This is inspired (copied and modified) in the function from daniel_dll.

function GetIpArray()
{
$cad="";
                                                                                
if  (isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND   
      $_SERVER['HTTP_X_FORWARDED_FOR']!="")
                  $cad=$_SERVER['HTTP_X_FORWARDED_FOR'];
                                                                                
if(isset($_SERVER['REMOTE_ADDR']) AND 
    $_SERVER['REMOTE_ADDR']!="")
                 $cad=$cad.",".$_SERVER['REMOTE_ADDR'];                                                                           
                                                                                
$arr=  explode(',',$cad);
                                                                                
return $arr;
}

//We check each ip in the array and we returns the first that is not a
//private ip.

function getIp()
{
  global $ip_private_list;
    $ip = "unknown";
    $ip_array=getIpArray();
   
    foreach ( $ip_array as $ip_s ) {
                                                                                
      if( $ip_s!="" AND !isIPInNetArray($ip_s,$ip_private_list)){
        $ip=$ip_s;
        break;
      }
    }
                                                                                                                                                                
  return($ip);
} ?>

Link to comment
Share on other sites

Good morning all!

 

darkfreaks:

Thank you for posting that.

This is going to be used for a toplist.

There is a jerk that has been a royal pain and is posting non sites

every day many times a day.

 

All of the files for the toplist are in my cgi dir.

So where will this go, where will I see the readout, and what do I call it ??

 

Thank you  Thank you  Thank you  !!!

Link to comment
Share on other sites

a toplist for ip's i spose ???  :P

 

 

let me tell you how the functions work first off then you can call them how you want to. private list allows you to manually input and array private IP's. the function ipisinnet determines if an IP adress is in the same network or not. the second function under it determines if it is in multiple networks and hidden (IE a proxy). the last function gets all of the arrayed IP's and the very very last function searches all the arrayed IP's to make sure it isnt listed as a private IP and if it is it returns one that is not a private hidden IP (IE a proxy)

Link to comment
Share on other sites

Let me go into more detail.

When someone signs up to add a site to the toplist,

I receive an email saying that they did so.

I am still confused as to where to put this script, and how to get it to output where I can see the results.

 

Like the 1st script that I posted ... It creates a log of the user's ip by having them hopefully click on the picture.

Link to comment
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.