Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mailing with php

Status
Not open for further replies.

funkytunaa

Technical User
Oct 9, 2005
116
AU
I've got a little subscription form on my website that calls a php script that does a few things, including writing the subscribers Name/email to a log file (text file) and the same for a referral box that is on the form, it also emails anyone that the subscriber puts in the referral box with a pre defined email in the php script.

The php script also checks the log file whether the email that is entered has already been subscribed and then points to a html file depending, also doesn't double up on subscription emails.

Now. I have a couple of queries that I can't seem to figure out.

1/ how many lines can the log file contain and review before it starts to throw up?

2/ Currently, the user can press the back button on the mouse and resend the form over and over again. Is there coding in PHP that can prevet this?

3/ I have put the text file that contains the emails in the root directory, below the public_html, is this secure? Because for the script to check the email address for multiple entries the file needs to be read/write.

Please ask me any questions if I have been a bit vague.

Cheers!!!
 
1. limits are the memory that you have allowed php to have and the timeouts (to a lesser extent)

2. yes. plenty of different ways. here is a mock-up of the method that I use

Code:
<?php
session_start();
if (isset($_POST['submit'])){
    processForm();
}else{
    displayForm();
}
function testUnique(){
    if (!isset($_SESSION['uid'])) return false;
    if (!isset($_POST['uid'])) return false;
    if (trim($_POST['uid']) !== $_SESSION['uid']) return false;
    return true;
}
function generateUID(){
    if (isset($_SESSION['uid'])){
        return $_SESSION['uid'];
    }else{
        $_SESSION['uid'] = uniqid("test_", true);
        return $_SESSION['uid'];
    }
}
function displayForm($msg=''){
    $msg = !empty($msg)?"<legend>$msg</legend>":'';
    $uid = generateUID();
    $field = isset($_POST['field']) ? $_POST['field'] : '';
    echo <<<HTML
<form method="post" action="{$_SERVER['PHP_SELF']}" >
    <fieldset style="width:40%;">
    $msg
    <input type="hidden" name="uid" value="$uid" />
    <input type="text" name="field" value="$field" />
    <input type="submit" name="submit" value="submit" />
    </fieldset>
</form>
HTML;
}
function processForm(){
    if (testUnique()){
        //processform
        //if form processes correctly kill the session vars
        killVars();
        displayForm("success");
    } else {
        //you may want to do something else here
        killVars();
        displayForm("refresh");
    }
    
}

function killVars(){
    unset($_SESSION['uid']);
    unset($_POST);
}
?>

3. no. it does not seem to be secure. you should place the file outside of the root directory or in a folder that has DENY ALL privileges in the web server. read/write privileges can be set at the file system level on any folder.
 
What sort of size do you think a file would have to get to? Although this shouldn't be too much of a problem because once a month I'll clear it anyhoo.

Thanks for the code too! I'll have to nut it out a little bit but it looks great.

Third...The file is below the html_public directory, so it is outside the root directory, even if I type something like


nothing comes up, I just don't want people to have access to view it. I tried that putting it in a directory with deny all but haven't been able to get it going as yet...probably because I'm thick! :)

Cheers!
CR
 
below" to me means inside the root. if the root directory is c:\inetpub\ outside the root would be, for example, c:\logfiles.

i have sometimes run php with a memory limit of 60MB without problem. i tend to run with only 8MB, however. as with all hardware sizing issue, it all depends what else you want the box to do
 
I figured that would be the case, so what I have done is I have set it up so that the text file sits below the root.

So if I type then it reads the files from the public_html directory, what I have done is put the text file in the directory below public_html so in the php file it calls it ../thefile.txt so even if I type it dumps the "../" part and appears in the URL bar.

That's a bit long winded, but I just wanted to make sure I am on the right track.

np I've only got the text file holding a name and email so it shouldn't be an issue.

If you like have a look at the website, download and read the online magazine, and subscribe. The more subscribers the better!!! Let me know what you think.


Thanks for the help btw.
 
just a thought, but log analysis can be quite process intensive and there are good programs that do it. the programs tend to be compiled rather than interpreted and some are opensource. just google for them. there is no reason why you can't deliver the outputs via php and use sys commands to generate the calls to the loganalysis etc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top