I've realized I should host my copyright text on my website. And since I take photos, some clients may wish to alter the copyright per an agreement. So, on the generic copyright page I wish to have a form input box where they can type their agreement number and the details of their copyright get displayed on page.

I plan to keep the agreements in a .txt file (.php if need be) with the name of the agreement number. So retrieval should be trivial. Though, I'm a guy with hardly any PHP knowledge.

Would a simple $_POST['var'] and $_GET['var'] work? I've never used _POST but I'm familiar with _GET. So, would _POST send the variable to the URL or save it to a global variable? On form submit I'd likely reload the page and fetch the custom agreement. If no agreement number is present I'd display the generic copyright, I should be able to figure the IF ELSE though.

In wraps, how does $_POST work and would the variable stay set if I reload the page or would I need a global variable? Does the global variable reset once they leave the site?
_POST doesn't save data to a global variable, you would need to use _SESSION for that. POST basically puts data for server side programs to use in stdin, while GET uses QUERY_STRING. I don't think the variable would stay when the user refreshes the page unless the user chose to submit the form data again.
None of the stuff you're talking about is static. The bad solution would be to store this in a client-side cookie. The medium solution would be a flatfile of client_username:license lines. The best solution would be a table in a database.
I'm not all for the MySQL table, since I currently have no way of editing/inserting content. If I ever get OOo to work I could do that, or if I find a dedicated program.

Regarding the flatfile, why can't I have clientusername.txt that's retrieved via a PHP script? Could I use stdin as Souvik mentioned, or am is $_POST out of the question?
You would either need to use a SQL table or a flat text file to store data, since $_SESSION and $_POST can change.
comicIDIOT wrote:
I'm not all for the MySQL table, since I currently have no way of editing/inserting content. If I ever get OOo to work I could do that, or if I find a dedicated program.

Regarding the flatfile, why can't I have clientusername.txt that's retrieved via a PHP script? Could I use stdin as Souvik mentioned, or am is $_POST out of the question?
What do you mean you have no way of editing/inserting content? I would sincerely hope your webhost has PHPMyAdmin installed, otherwise they're not a very good host. Smile Or you could write yourself a Cemetech ACP-style manager, it's not too challenging. I think perhaps you are a bit vague on what stdin and $_POST actually are/do, no offense intended?
Regarding the $_POST and stdin thing, you use stdin to get POST data when writing Bash CGI scripts. PHP just lets you use the $_POST array to access everything.
POST and GET variables are passed along with the HTTP page request. PHP takes the data in the form the browser sends it to the server and populates the $_POST and $_GET arrays for you; it does not, however, save anything automatically for you. The difference between POST and GET is largely semantic; you would typically use GET when retrieving information from the server (to read this topic we use GET with a t parameter of 6577) and POST when sending data to the server (to reply to this thread we use POST with a t parameter of 6577 and a message parameter containing our reply, amongst others). The PHP script then does what it has to (retrieving posts or adding a new one), but PHP itself will not do anything to automatically store data.

I would agree with Kerm that storing the data in a database would be the easiest solution. If you are using MySQL then the MySQL GUI Tools are relatively decent if you don't fancy using the command-line tools. phpMyAdmin is an absolutely horrible piece of software so I'd avoid steering clear of it if at all possible; if your host doesn't provide external access to databases then I'd recommend Adminer (previously: phpMinAdmin) as a web-based client.
KermMartian wrote:
comicIDIOT wrote:
I'm not all for the MySQL table, since I currently have no way of editing/inserting content. If I ever get OOo to work I could do that, or if I find a dedicated program.

Regarding the flatfile, why can't I have clientusername.txt that's retrieved via a PHP script? Could I use stdin as Souvik mentioned, or am is $_POST out of the question?
What do you mean you have no way of editing/inserting content? I would sincerely hope your webhost has PHPMyAdmin installed, otherwise they're not a very good host. Smile Or you could write yourself a Cemetech ACP-style manager, it's not too challenging. I think perhaps you are a bit vague on what stdin and $_POST actually are/do, no offense intended?
I do, but I'd like to not login to cPanel to make changes. It'd be a lot more efficient for me to plop a .txt in a directory via my FTP program.

The copyright data will be public (i.e. "To look up a copyright agreement, type in the number below:") as the information will be in the EXIF data on photos (if applicable).

As far as MySQL being easier, I see it being more secure and since I lack computer side tools (aside from Open Office, which I haven't gotten it to open my DB yet) a text file for each copyright seems rather ideal. If I move on to letting clients login, then I'd most certainly use a MySQL DB or whatever secure system I download uses.

Regarding $_POST & $_GET, I'd be able to retrieve the posted information after the form as loaded the requested page, correct?

On another idea tangent, I'm starting to think I put the copyright agreement number in the URL much like domain.com/copyright/###### instead of just domain.com/copyright. Then I'd be able to store the exact copyright URL for that particular photo within it's EXIF data.
comicIDIOT wrote:
I do, but I'd like to not login to cPanel to make changes. It'd be a lot more efficient for me to plop a .txt in a directory via my FTP program.

If you aim to make these files writeable from a PHP script then you'll also need to make sure the file permissions are set up correctly (on my host, at least, files or directories created through FTP are not writeable from PHP by default) and watch out for two scripts trying to access the same file at the same time (see PHP's file locking functions for directions).

Quote:
Regarding $_POST & $_GET, I'd be able to retrieve the posted information after the form as loaded the requested page, correct?

Yes, PHP will automatically take the data POSTed via a form and populate the $_POST array for you. Use isset($_POST['input_field_name']) to check whether a particular field has been submitted or not.

Quote:
On another idea tangent, I'm starting to think I put the copyright agreement number in the URL much like domain.com/copyright/###### instead of just domain.com/copyright. Then I'd be able to store the exact copyright URL for that particular photo within it's EXIF data.

Sounds like a good idea. mod_rewrite could be used to turn an URL in that form to something like /copyright.php?id=###### for you if you need more flexibility.
Flatfiles are so Perl-y.
benryves wrote:
comicIDIOT wrote:
I do, but I'd like to not login to cPanel to make changes. It'd be a lot more efficient for me to plop a .txt in a directory via my FTP program.

If you aim to make these files writeable from a PHP script then you'll also need to make sure the file permissions are set up correctly (on my host, at least, files or directories created through FTP are not writeable from PHP by default) and watch out for two scripts trying to access the same file at the same time (see PHP's file locking functions for directions).
I'm not going to be editing them from my website, so that shouldn't be a concern. But good to know for reference.

Quote:
Quote:
Regarding $_POST & $_GET, I'd be able to retrieve the posted information after the form as loaded the requested page, correct?

Yes, PHP will automatically take the data POSTed via a form and populate the $_POST array for you. Use isset($_POST['input_field_name']) to check whether a particular field has been submitted or not.
Fantastic!

Quote:
Quote:
On another idea tangent, I'm starting to think I put the copyright agreement number in the URL much like domain.com/copyright/###### instead of just domain.com/copyright. Then I'd be able to store the exact copyright URL for that particular photo within it's EXIF data.

Sounds like a good idea. mod_rewrite could be used to turn an URL in that form to something like /copyright.php?id=###### for you if you need more flexibility.
[/quote]I like that idea. How would I go about sending data from a form field to the URL so it's universal for both photos and submitting via the online form.


Appreciate the help so for guys Smile
comicIDIOT wrote:
I like that idea. How would I go about sending data from a form field to the URL so it's universal for both photos and submitting via the online form.

I'm afraid I have no idea what this question means. Could you please elaborate?
When a visitor submits the form, the data in the field would get appended to the URL and the page reloaded/redirected from there.

Code:
http://domain.com/copyright.php
http://domain.com/copyright.php?id=sentfromform


Much like the search script here on Cemetech, actually.

If it's too much work, for a newbie like me here, I'm not going to worry about it. As my objective is to see how it'd be done that set about doing it. Right now, the $_POST & $_GET seem entirely possible for me to do now that I understand $_POST a better.
You would use the same PHP script again in your <form> tag, so it would be <form action="copyright.php" method="GET">. Then you would use isset() to see if there was any data in GET that was passed to the script.
Okay. I don't follow the method though. Instead of POST it's GET? How do I tell the form to send the info to a variable called 'id' or 'copyright?' would the action just be 'copyright.php?id' or do I select the variable/action from the <input> tag?
It can be either POST or GET, but choose GET if you want the ?id after copyright.php.
Sweet. I got it working, for the basic part. I'm going to start working on the text files and retrieval after I finish editing the photos I have. I'll post any hurdles I run into, as well as the final result.

Thanks guys!

UPDATE: Ran into a snag. I can't get my IF ELSE to work correctly. Here's what I have so far. And feel free to try it out at the link above.


Code:
<div id="info">
           
                <span class="h2" id="rights"></span>
                    <h2>Copyright</h2>
                   
                    <?php
                       
                       if (isset($_GET['id']) AND !file_exists('path/'.$crid.'.php')) { echo ('<h3>Error Retrieving Copyright</h3><p>No Copyright matches the Unique Identifier. Please double check the ID, if it is correct, please contact Alex Glanville.</p>'); }
                       
                       if (file_exists('path/'.$crid.'.php')) {
                             if (isset($_GET['id'])) { include('path/'.$crid.'.php'); }
                       } else {
                          include('path/generic.php');
                       }
                   
                   ?>
                   <h3>Copyright Look Up</h3>
                    <p>
                       <form action="copyright.php" method="get">
                          <input name="id">
                          <button type="submit">Look Up</button>
                       </form>
                    </p>
                   
            </div>


generic.php contains

Code:
<h3>Generic Copyright</h3>
<p>This page is still under construction.</p>


For an example, type test in the form.
Try changing AND to &&.
And that would fix the IF ELSE?
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement