Results 1 to 10 of 10

Thread: webpage help

  1. #1
    Senior Member deftones12's Avatar
    Join Date
    Jan 2003
    Location
    cali forn i a
    Posts
    333

    webpage help

    hey im not a webdesigner or nothing, so im new to all this.Im not gettin in to webdesigning im just makin one to have one and might build more on it later. i just wanna make a form on my page where it sais "Enter your name here" and i have that and a lil box and a submit button, but how can i make it POST to a file like names.txt to my root folder so i can see names that have visited my site. And also if i can make that into a popup that'd be great, they'd have to enter a name and push submit then it lets them to the site, and if they dont they get access denied or something. I know that'd have to be a javascript popup and i googled that and found the script but i dunno where to put it in the script and how the POST >. names.txt or that stuff goes. Im using dreamweaver.

  2. #2
    BANNED
    Join Date
    Nov 2003
    Location
    San Diego
    Posts
    724
    Here's a javascript tutorial I think you should be able to find what you're looking for in it. I didn't write it. It came off of a cd I got with HTML for dummies.

    I've been looking through it and don't see anything that explains what you are asking though. I thought I had something that explained what you are asking specifically. I'll keep lookig for it.

    Edit: Actually it's online here http://www.webteacher.com/javascript/index.html but I think it's nice in this lil zip file so I'm gonna leave it on here.

  3. #3
    Senior Member deftones12's Avatar
    Join Date
    Jan 2003
    Location
    cali forn i a
    Posts
    333
    thanks alot muert0.

  4. #4
    Elite Hacker
    Join Date
    Mar 2003
    Posts
    1,407
    I don't see how you could write to a file on the server with javascript as it is client side not server side. You can do it fairly easily if your server supports php.
    Code:
    <form action="process.php" method="post">
    Enter your name: <input type="text" name="visitor_name" size="10">
    <input type="submit" value="Submit">
    </form>
    that is the first page with the form. Then you make a page called process.php with the following code:
    PHP Code:
    <?php
    $visitor 
    $_POST['[b]visitor_name[/b]'];
    $fp fopen('c:/visitors.txt''a');
    if(!
    $fp){
        echo 
    "put an error message here.  Means it failed to open or create the text file.";
    }
    $outputstring $visitor."\n\n";
    fwrite($fp$outputstring);
    ?&
    gt
    the name you set for the field in the form has to match the name coming in when processing the post information. Depending on permissions on the file you're trying to write to, that should work. Peace.

    [edit]
    just thought of something. You're pretty safe in this case for input, cause it's just a text file. However, if you were writing these things to a page on your site, You would want to look into some functions like html_special_chars() and strip_tags() (see the php manual). If you do not process the input correctly a user could put code in the form that would execute on your page and that could be bad. So please look into input validation functions if you're displaying their input on a webpage. Also, even for a text file you may want to put a limit on length so that it is not flooded with text. just add an if statement right after the
    $visitor = $_POST['visitor_name'];
    line, that reads.
    if(strlen($visitor) > 40){
    echo "input must be less than 40 characters";
    }
    You can change the length to whatever you want though. Peace.
    [/edit]

  5. #5
    Senior Member deftones12's Avatar
    Join Date
    Jan 2003
    Location
    cali forn i a
    Posts
    333
    im using apache thanks. thats what i was lookin for. thats perfect thanks so much.

  6. #6
    Elite Hacker
    Join Date
    Mar 2003
    Posts
    1,407
    [edit]darnit, you edited your post. You had a long list of questions, these are the answers I thought were appropriate. I hope you remember your questions .[/edit]
    I couldn't get it to work with a popup, but I just tested the code as is and it worked. As for your many questions.

    1. you might be able to do it in a popup, but what I tried didn't work.
    2. It doesn't necessarily have to be .php. It all depends on your apache configuration. If you have it set for:
    AddType application/x-httpd-php .php .html
    in your webserver config .html will execute as php as needed.
    3. don't know what you're talking about. html is html. You should be able to leave them as .html
    4. The file to process it (popup as referenced by you) for my way has to be a php page, but not necessarily with a .php extension as illustrated above. You can do it with other things such as asp or jsp. It all depends on what you/your host have installed. You need to find out if they have any server side scripting stuff installed for the webserver. possibly just cgi.
    5. I'm pretty sure dreamweaver can make .php pages. I believe they have syntax highlighting for php also. I guess any editor can make .php pages, it's just an extension.
    6. Not really. If you copy my code exactly and php is installed, and you save the page as process.php, it should work. So it's not that hard. Plus they have really good documentation.
    http://www.php.net
    check it out.
    if you change the file process.php to process.html you have to change it accordingly in the code.
    i.e. action="process.html"
    Peace.

  7. #7
    Senior Member deftones12's Avatar
    Join Date
    Jan 2003
    Location
    cali forn i a
    Posts
    333
    hey it sais 'Method Not Allowed". I know its not cuz of permissions cuz i even did chmod 777 names.txt and names.php and it still wouldnt do it. Also it sais "The requested POST is not allowed for the URL /names.php. I dont think its permission problems so i dunno, any ideas? i put in my index1.html pages your first script there, then in names.php i put your second script, and i did change the part that you said to change if i changed process.php to names.php, so i dunno.

  8. #8
    Elite Hacker
    Join Date
    Mar 2003
    Posts
    1,407
    Is this your server or someone elses? Cause it sounds like they disabled POST requests in the apache configuration. If it's yours look for some <Limit tag in there about POST, if it's not yours, just change the method to GET in the form. then change the names.php to say $_GET['visitor_name'] instead of POST. That is the simpler fix. Peace.

  9. #9
    Senior Member deftones12's Avatar
    Join Date
    Jan 2003
    Location
    cali forn i a
    Posts
    333
    k i found somethin i'll try it out.

  10. #10
    Senior Member deftones12's Avatar
    Join Date
    Jan 2003
    Location
    cali forn i a
    Posts
    333
    hey i uncommented some of the stuff that was stopping POST and GET and PUT and directories with it and pointed it with to the directory i made. Can i send you the httpd.conf and have you take a look and see what you think?

Posting Permissions

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