Importing and Exporting Variables
Moderator: General Moderators
Importing and Exporting Variables
I know a bit of php (really I've code off of tutorials), but I'm stumped on this.
Is there a code that takes a text file that is uploaded onto your website, and extracts a number from it (and turns it into a variable). Then at the end of the code write over the original text file with the variable's new value?
Thanks!
Is there a code that takes a text file that is uploaded onto your website, and extracts a number from it (and turns it into a variable). Then at the end of the code write over the original text file with the variable's new value?
Thanks!
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
The file will start out just containing a 1. Then hopefully (if the rest of my code works how it should) I want the file to be 2. Then next time somebody loads up the page it'll run through procedures and then the file will have a value of 3. So it is one # that after each runthrough will go up by 1. (I can program it going up, i just need to program how to change that # in the text file to a variable and then export it back to the text file).
Thanks for your speedy replies!
Thanks for your speedy replies!
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Note, I've changed the username's and passwords to x's for security reasons. (Also I haven't added the break tags in yet).
It'll keep on going on and on but you get the basic jist. Now I need to know how to have this variable in a test file. I want it so at the beggining of the code the # that is in the text file is what the variable (named variable) has the value of. Then at the end I want the new value of the variable to overwrite the original value of the variable.
EDIT: I'm using this code as a confirmation page for when someone signs up for an account. I don't want to bother with php forms, so I've decided to program in the username/password combinations into the login form, and just have them display a different combination everytime somebody signs up.
Code: Select all
<?php
if ($variable == 1) {
print "Username xxxx Password xxxxxxx"; $variable = $variable + 1; } else {
}
if ($variable == 2) {
print "Username xxxx Password xxxxxx"; $variable = $variable + 1; } else {
}
if ($variable == 3) {
print "Username xxxx Password xxxxxx"; $variable = $variable + 1; } else {
}
?>EDIT: I'm using this code as a confirmation page for when someone signs up for an account. I don't want to bother with php forms, so I've decided to program in the username/password combinations into the login form, and just have them display a different combination everytime somebody signs up.
- shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
- Contact:
maybe i dont get what your saying but you want the user to confirm their confirmation as a new user (possibly with their email address???)
if this is true then just use a mysql database to store the usernames, check if the username is already taken, then send the user a email (provided they supplied a valid email address) that says "click here to confirm"
if im right in what you want then i can (and many others) can provide the code for that
if this is true then just use a mysql database to store the usernames, check if the username is already taken, then send the user a email (provided they supplied a valid email address) that says "click here to confirm"
if im right in what you want then i can (and many others) can provide the code for that
No, what I'm trying to do is this:
They user will type in their first name and e-mail. Then when they hit sign-up the confirmation page will display a username/password set. So using the code above it'll just go through a list of usernames and passwords I've already hard coded, and then it'll pick the first one availible (by find what number the variable is at).
EDIT: Although if you can do it your way and it isn't that hard to set-up (if it'll be easier then the solution that I've set up) then I'm all for it. As I side note I'll also need a log-in code if we do it that way.
They user will type in their first name and e-mail. Then when they hit sign-up the confirmation page will display a username/password set. So using the code above it'll just go through a list of usernames and passwords I've already hard coded, and then it'll pick the first one availible (by find what number the variable is at).
EDIT: Although if you can do it your way and it isn't that hard to set-up (if it'll be easier then the solution that I've set up) then I'm all for it. As I side note I'll also need a log-in code if we do it that way.
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
Well, file_get_contents returns the file as a string. So...
Check out the PHP documentation for handy functions that imitate file_get_contents and it's kindred if you don't have PHP 5.
Read the documentation
Code: Select all
$contents_of_file = file_get_contents($name_of_file);
//edit it
file_put_contents($name_of_files,$contents_of_file);Read the documentation