PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old October 15th, 2009, 11:00 AM
cjozwiak cjozwiak is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 7 cjozwiak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 46 m
Reputation Power: 0
php5 - Html form to secure excel document

I have an html form that posts the results to an excel csv file.
In FrontPage I could put the csv file in a _private folder and it would not be accessible on the internet. I am now using dreamweaver and would like to do the same sort of thing with the csv file.
I have tried moving the csv file to another folder
(ei: $filename = "_private/formresults.csv";) but it doesn't work.
Any ideas?






$firstname = $_POST['FirstName'];
$lastname = $_POST['LastName'];
$email = $_POST['email'];
$address = $_POST['Address'];
$city = $_POST['City'];
$state = $_POST['State'];
$phone = $_POST['Phone'];
$zip = $_POST['Zip'];
$military = $_POST['Military'];



//now we open the file using the a flag, this will create the file if
//it does not exist, and puts the pointer(where it starts writing) at the
//end of the file
$filename = "formresults.csv";
$handle = fopen($filename, 'a');

//now we prepare our string to be added:
$string_to_add = "$firstname,$lastname,$email,$address,$city,$state, $phone,$zip,$military" . "\n";
fwrite($handle, $string_to_add);

//now close the file
fclose($handle);

Reply With Quote
  #2  
Old October 15th, 2009, 01:56 PM
MatthewJ MatthewJ is offline
Contributing User
Click here for more information.
 
Join Date: May 2007
Location: Davenport, Iowa
Posts: 564 MatthewJ User rank is Private First Class (20 - 50 Reputation Level)MatthewJ User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 21 h 23 m 45 sec
Reputation Power: 3
You should do a Google search for "Restricting directory access" for whatever server type you are using, that should give you an idea of how to do it.

Reply With Quote
  #3  
Old October 15th, 2009, 02:41 PM
cjozwiak cjozwiak is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 7 cjozwiak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 46 m
Reputation Power: 0
Html form to secure excel document

Quote:
Originally Posted by MatthewJ
You should do a Google search for "Restricting directory access" for whatever server type you are using, that should give you an idea of how to do it.


I will do some research on that. Thanks for pointing me in the right direction.

Reply With Quote
  #4  
Old October 15th, 2009, 03:53 PM
IAmALlama IAmALlama is offline
Me
Click here for more information. Click here for more information
Click here for more information
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 1,937 IAmALlama User rank is Private First Class (20 - 50 Reputation Level)IAmALlama User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 5 Days 1 h 54 m 18 sec
Reputation Power: 4
what type of server do you use? In apache it could be as simple as putting a file named .htaccess with nothing more than "deny from all" in any folder you want to deny access to. PHP would still have access to said folder, just people can't visit it through the web server.
Comments on this post
MatthewJ agrees: Coming from Frontpage, I assumed it was going to be IIS

Reply With Quote
  #5  
Old October 15th, 2009, 04:27 PM
cjozwiak cjozwiak is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 7 cjozwiak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 46 m
Reputation Power: 0
Quote:
Originally Posted by IAmALlama
what type of server do you use? In apache it could be as simple as putting a file named .htaccess with nothing more than "deny from all" in any folder you want to deny access to. PHP would still have access to said folder, just people can't visit it through the web server.


I just spoke to our web server company and we are on appache. They are setting up the htaccess for me now. I don't know anything about that but will learn soon. Will the code have to be changed for me to hit the spreadsheet?
You guys are great!

Reply With Quote
  #6  
Old October 15th, 2009, 06:18 PM
IAmALlama IAmALlama is offline
Me
Click here for more information. Click here for more information
Click here for more information
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 1,937 IAmALlama User rank is Private First Class (20 - 50 Reputation Level)IAmALlama User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 5 Days 1 h 54 m 18 sec
Reputation Power: 4
the shouldn't have to be changed unless there is a different folder you want to save it to. like I said before, you just need to put a .htaccess file in the folder and put nothing but "deny from all" (no quotes) inside that file. that will do exactly what it says, deny access to all people who try to access the folder through the website. Other programs like PHP will still have full access to anything in the folder because it doesn't have to go through apache to get to there.

.htaccess files are just a way of setting config options for apache on a directory basis. Generally any folders with a .htaccess file and any subdirectories under that folder will be affected by the file. They are mostly used to URL rewriting which gets you the clean URLs that you see on most sites nowadays.

Reply With Quote
  #7  
Old October 19th, 2009, 05:24 PM
cjozwiak cjozwiak is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 7 cjozwiak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 46 m
Reputation Power: 0
Html form to secure excel document

Quote:
Originally Posted by IAmALlama
the shouldn't have to be changed unless there is a different folder you want to save it to. like I said before, you just need to put a .htaccess file in the folder and put nothing but "deny from all" (no quotes) inside that file. that will do exactly what it says, deny access to all people who try to access the folder through the website. Other programs like PHP will still have full access to anything in the folder because it doesn't have to go through apache to get to there.

.htaccess files are just a way of setting config options for apache on a directory basis. Generally any folders with a .htaccess file and any subdirectories under that folder will be affected by the file. They are mostly used to URL rewriting which gets you the clean URLs that you see on most sites nowadays.


I'm still not populating the spreadsheet so I must be doing something wrong.
The .htaccess page the web server company set up is password protected:
AuthType Basic
AuthName "Admin Access"
AuthUserFile /web/acl/deprez.pwd
Require valid-user

It is in a folder called excel
I added to this folder my php page and the csv spreadsheet.
The forms action is "excel/clientprofile2.php"

Do I need to put anything on the form or php page indicating the use of the htaccess page?

Reply With Quote
  #8  
Old October 20th, 2009, 09:35 AM
cjozwiak cjozwiak is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 7 cjozwiak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 46 m
Reputation Power: 0
Html form to secure excel document

Quote:
Originally Posted by cjozwiak
I'm still not populating the spreadsheet so I must be doing something wrong.
The .htaccess page the web server company set up is password protected:
AuthType Basic
AuthName "Admin Access"
AuthUserFile /web/acl/deprez.pwd
Require valid-user

It is in a folder called excel
I added to this folder my php page and the csv spreadsheet.
The forms action is "clientprofile2.php"

Do I need to put anything on the form or php page indicating the use of the htaccess page?


This was wrong. Don't know what I was thinking.
The form points to the php file not located in the excel folder.
The php file points to the excel folder which houses the csv file. (excel/filename.csv) Unfortunately it doesn't populate the spreadsheet. Even if I use a folder without htaccess the code doesn't seem to want to populate the csv. It only seems to work if they are on the same level. Any clues?

Reply With Quote
  #9  
Old October 20th, 2009, 02:08 PM
IAmALlama IAmALlama is offline
Me
Click here for more information. Click here for more information
Click here for more information
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 1,937 IAmALlama User rank is Private First Class (20 - 50 Reputation Level)IAmALlama User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 5 Days 1 h 54 m 18 sec
Reputation Power: 4
try something like this:

PHP Code:
<?php
$csvFileName 
"test.csv";

if(isset(
$_POST) && !empty($_POST)){
    
$firstname $_POST['FirstName']; 
    
$lastname $_POST['LastName']; 
    
$email $_POST['email']; 
    
$address $_POST['Address']; 
    
$city $_POST['City'];
    
$state $_POST['State']; 
    
$phone $_POST['Phone'];
    
$zip $_POST['Zip'];
    
$military $_POST['Military'];
    
    
$lineOut "$firstname,$lastname,$email,$address,$city,$state,  $phone,$zip,$military\n";
    
    
file_put_contents($csvFileName,$lineOut,FILE_APPEN  D);
    echo 
"Your data has been saved.";
} else {
    echo<<<FORM
<form method='post' action='?'>
First Name: <input type='text' name='FirstName'><br />
Last Name: <input type='text' name='LastName'><br />
Email: <input type='text' name='email'><br />
Address: <input type='text' name='Address'><br />
City: <input type='text' name='City'><br />
State: <input type='text' name='State'><br />
Phone: <input type='text' name='Phone'><br />
Zip: <input type='text' name='Zip'><br />
Military: <input type='text' name='Military'><br />
<input type='submit' value='Save'>
</form>
FORM;
}
?>

Reply With Quote
  #10  
Old October 20th, 2009, 02:46 PM
cjozwiak cjozwiak is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 7 cjozwiak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 46 m
Reputation Power: 0
Quote:
Originally Posted by IAmALlama
try something like this:

PHP Code:
<?php
$csvFileName 
"test.csv";

if(isset(
$_POST) && !empty($_POST)){
    
$firstname $_POST['FirstName']; 
    
$lastname $_POST['LastName']; 
    
$email $_POST['email']; 
    
$address $_POST['Address']; 
    
$city $_POST['City'];
    
$state $_POST['State']; 
    
$phone $_POST['Phone'];
    
$zip $_POST['Zip'];
    
$military $_POST['Military'];
    
    
$lineOut "$firstname,$lastname,$email,$address,$city,$state,  $phone,$zip,$military\n";
    
    
file_put_contents($csvFileName,$lineOut,FILE_APPEN  D);
    echo 
"Your data has been saved.";
} else {
    echo<<<FORM
<form method='post' action='?'>
First Name: <input type='text' name='FirstName'><br />
Last Name: <input type='text' name='LastName'><br />
Email: <input type='text' name='email'><br />
Address: <input type='text' name='Address'><br />
City: <input type='text' name='City'><br />
State: <input type='text' name='State'><br />
Phone: <input type='text' name='Phone'><br />
Zip: <input type='text' name='Zip'><br />
Military: <input type='text' name='Military'><br />
<input type='submit' value='Save'>
</form>
FORM;
}
?>


I get an http 500 error from that code.

Reply With Quote
  #11  
Old October 20th, 2009, 04:39 PM
IAmALlama IAmALlama is offline
Me
Click here for more information. Click here for more information
Click here for more information
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 1,937 IAmALlama User rank is Private First Class (20 - 50 Reputation Level)IAmALlama User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 5 Days 1 h 54 m 18 sec
Reputation Power: 4
It worked fine on my server. a 500 error is "A generic error message, given when no more specific message is suitable". you should look to see if there is an error log somewhere and try to resolve whatever problem it is displaying. You also might want to double check permissions to make sure that the folder you want to save the file in is writable to the web server.

Reply With Quote
  #12  
Old October 26th, 2009, 10:14 AM
cjozwiak cjozwiak is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 7 cjozwiak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 46 m
Reputation Power: 0
Quote:
Originally Posted by IAmALlama
It worked fine on my server. a 500 error is "A generic error message, given when no more specific message is suitable". you should look to see if there is an error log somewhere and try to resolve whatever problem it is displaying. You also might want to double check permissions to make sure that the folder you want to save the file in is writable to the web server.



Thank you for all of your help. I changed the permissions on my spreadsheet to 777 and now the form is perfect.
I am ready to convert the rest of the forms on the website. What a relief.
Thanks again
Colleen

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > php5 - Html form to secure excel document


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek