Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: Um... script? Please read!

  1. #11
    Join Date
    Apr 2010
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by BLiZZaRD View Post
    Yes I get that now, I thought you wanted it displayed on the page.

    Now that you don't it was very easy and I am all done. Here you go:

    PHP Code:
    <?
    $userName 
    $_POST["User"];
    $agent $_SERVER['HTTP_USER_AGENT'];
    $uri $_SERVER['REQUEST_URI'];
    $ip $_SERVER['REMOTE_ADDR'];
    $ref $_SERVER['HTTP_REFERER'];
    $visitTime date("r");
    if (
    $_GET['submit']=="true")
     {
     
    $logLine "$visitTime - IP: $ip || UserName:  $userName  ||  User Agent: $agent  || Page: $uri || Referrer: $ref\n";
      
    $fp fopen"visitorlog.txt""a" );
      
    fwrite$fp$logLine );
      
    fclose$fp );
      
    header("Location: http://theOtherSite.com"); //Change this to the site you want them redirected to
     
    }
    ?>
    <html>

    <head>
    <title>User Info</title>
    </head>

    <body>
    <form name="user" method="post" action="form.php?submit=true"> //Change 'form.php' to whatever the name of the file where this code is placed is called.
    <p>User Name:&nbsp;<input type="text" name="User" value="User"></p>
    <p align="center"><input type="submit" name="submit" value="Submit"></p>
    </form>
    </body>

    </html>
    Please note the two edit places ( followed by //Change this line.... ) Make those changes and you are off and running.
    Everything has worked so far, but when I try to access visitorlog.txt, it tells me that the page isn't found. I've made sure it has been uploaded into the correct directory twice now... Do you have any ideas of why I'd continue to get 404 errors?

    Edit: Excuse my ignorance, I was typing in vistorlog instead of visitor.

    Thank you so much!

  2. #12
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    You are very welcome.
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  3. #13
    Join Date
    Apr 2010
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    I have one more question, hopefully you haven't left this thread completely and will never come back...

    I've tested the script out a couple of times and it works flawlessly, but all of the data is placed on one line instead of having line breaks after every form is submitted. Is there anyway to fix this? I think I can manage without the line breaks but it is an eye sore.

  4. #14
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Yup.

    Change this line:

    PHP Code:
    $logLine "$visitTime - IP: $ip || UserName:  $userName  ||  User Agent: $agent  || Page: $uri || Referrer: $ref\n"
    To this:

    PHP Code:
    $logLine "$visitTime - IP: $ip || UserName:  $userName  ||  User Agent: $agent  || Page: $uri || Referrer: $ref \n\n"
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  5. #15
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I haven't followed all of the details in this discussion, but I think this answers your question:

    This line determines the format:
    $logLine = "$visitTime - IP: $ip || UserName: $userName || User Agent: $agent || Page: $uri || Referrer: $ref\n";

    Note that \n is the representation of a line break. It's the same as an actual return, but it's shorthand within the code. You can also use a real line break in the text (if that doesn't look too strange within the code).


    The real question here is what to do about the format:
    Yes, it's problematic having it all on one line, but what do you want to do instead?
    The way that it is setup now, you have || separating the information, and new lines separating the different instances of data.

    Perhaps here's a better way:
    $logLine = "$visitTime - IP: $ip
    UserName: $userName
    User Agent: $agent
    Page: $uri
    Referrer: $ref
    ----------------";


    Does that look nicer to you? You can format it in any way you like, though the one-line, one-item format is very common and can be useful later if, for example, you ever want to insert this into a database. (It's possible to use the new format I suggested as well, just not as standard.)



    EDIT: Looks like I posted at the same time as BLiZZaRD. His answer is for having two lines between the entries (a blank line separating them), and mine is to have each item of each entry as a new line. Either one will work, so choose what you like best.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. The Following User Says Thank You to djr33 For This Useful Post:

    Envy (04-14-2010)

  7. #16
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Good catch Daniel, I left it one line instead of separating everything for ease of use. And it seemed a tad silly to just have a user name input box and a submit button as the only content on the page. So I figured there would either be more already, or more coming later
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  8. #17
    Join Date
    Apr 2010
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by BLiZZaRD View Post
    Good catch Daniel, I left it one line instead of separating everything for ease of use. And it seemed a tad silly to just have a user name input box and a submit button as the only content on the page. So I figured there would either be more already, or more coming later
    Quote Originally Posted by djr33 View Post
    I haven't followed all of the details in this discussion, but I think this answers your question:

    This line determines the format:
    $logLine = "$visitTime - IP: $ip || UserName: $userName || User Agent: $agent || Page: $uri || Referrer: $ref\n";

    Note that \n is the representation of a line break. It's the same as an actual return, but it's shorthand within the code. You can also use a real line break in the text (if that doesn't look too strange within the code).


    The real question here is what to do about the format:
    Yes, it's problematic having it all on one line, but what do you want to do instead?
    The way that it is setup now, you have || separating the information, and new lines separating the different instances of data.

    Perhaps here's a better way:
    $logLine = "$visitTime - IP: $ip
    UserName: $userName
    User Agent: $agent
    Page: $uri
    Referrer: $ref
    ----------------";


    Does that look nicer to you? You can format it in any way you like, though the one-line, one-item format is very common and can be useful later if, for example, you ever want to insert this into a database. (It's possible to use the new format I suggested as well, just not as standard.)



    EDIT: Looks like I posted at the same time as BLiZZaRD. His answer is for having two lines between the entries (a blank line separating them), and mine is to have each item of each entry as a new line. Either one will work, so choose what you like best.
    I'll try that right now and reply with the results...

    Yeah, I only needed the form as I'm just making the rest of the content simple HTML.

    Edit: It works perfectly, thank you so much, to the both of you for being so helpful.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •