Jump to content

Redirect or error if the code doesn't exist in code.txt


FocuSoft

Recommended Posts

I have in promotie.php the next form:

<form accept-charset="UTF-8" action="redirect.php">
  <input name="code" type="text" id="code" maxlength="15" />
  <input type="submit" value="Submit"/>
</form>

In redirect.php I have this code:

<?php
header('Location: download.php?code='.$_POST['code']);
?>
What I want to do is the next thing: I will create a file code.txt, where I write on each line my promotional codes.

 

Now how can I redirect to promotieerror.php or show a error if the code that was writed by the user doesn't exist in code.txt ?

P.S.: I don't want to use MySQL/Databases.

Thanks in advance for help.

Thanks for the answer but not this was my needs.

 

In this form my users input a promotional code that I send to them by email. I don't use databases. Remember that.

 

Now I put writed by hand in a code.txt file all promotional codes that I want to send.

 

When a user come to my webpage form they will input the code received, but if they input a wrong code that doesn't exist in code.txt they will not be redirected to download.php page, they will be redirected to promotieerror.php .

 

That I need, is that possible? Thanks for helping.

Yes it is possible, to write something to a file :

1 - Open code.txt (fopen()).

2- Write the promotional code (fwrite()).

3- Close code.txt (fclose()).

To read something from the file :

1 - Open code.txt (fopen()).

2- Depending on how you saved the enteries in code.txt, extract your promotional code.

3- Close code.txt (fclose()).

 

Or you can simply use a database, actually this is one reason why databases are there for.

Yes it is possible, to write something to a file :

1 - Open code.txt (fopen()).

2- Write the promotional code (fwrite()).

3- Close code.txt (fclose()).

To read something from the file :

1 - Open code.txt (fopen()).

2- Depending on how you saved the enteries in code.txt, extract your promotional code.

3- Close code.txt (fclose()).

 

Or you could just use file_put_contents() and file_get_contents():

 

 

In this form my users input a promotional code that I send to them by email. I don't use databases. Remember that.

 

Did you visit the link? It's used to write to text files.

I don't need to use

 

1 - Open code.txt (fopen()). and 2- Write the promotional code (fwrite()). I will write manually the codes here.

 

I just need to

 

1 - Open code.txt (fopen())

2 - Check if the code exist in code.txt

3 - Close code.txt (fclose())

4 - If exist redirect to download.php

5 - If not exist redirect to promotieerror.php

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.