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.

Edited by FocuSoft
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Edited by FocuSoft
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.