FocuSoft Posted November 22, 2013 Share Posted November 22, 2013 (edited) 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 November 22, 2013 by FocuSoft Quote Link to comment https://forums.phpfreaks.com/topic/284162-redirect-or-error-if-the-code-doesnt-exist-in-codetxt/ Share on other sites More sharing options...
cyberRobot Posted November 22, 2013 Share Posted November 22, 2013 So are you just wondering how to write something to a text file? If so, check out file_put_contents(): http://us1.php.net/file_put_contents Quote Link to comment https://forums.phpfreaks.com/topic/284162-redirect-or-error-if-the-code-doesnt-exist-in-codetxt/#findComment-1459520 Share on other sites More sharing options...
FocuSoft Posted November 22, 2013 Author Share Posted November 22, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/284162-redirect-or-error-if-the-code-doesnt-exist-in-codetxt/#findComment-1459523 Share on other sites More sharing options...
JIXO Posted November 22, 2013 Share Posted November 22, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/284162-redirect-or-error-if-the-code-doesnt-exist-in-codetxt/#findComment-1459527 Share on other sites More sharing options...
cyberRobot Posted November 22, 2013 Share Posted November 22, 2013 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(): http://www.php.net/file_put_contents/ http://www.php.net/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. Quote Link to comment https://forums.phpfreaks.com/topic/284162-redirect-or-error-if-the-code-doesnt-exist-in-codetxt/#findComment-1459528 Share on other sites More sharing options...
FocuSoft Posted November 22, 2013 Author Share Posted November 22, 2013 (edited) 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 November 22, 2013 by FocuSoft Quote Link to comment https://forums.phpfreaks.com/topic/284162-redirect-or-error-if-the-code-doesnt-exist-in-codetxt/#findComment-1459529 Share on other sites More sharing options...
cyberRobot Posted November 22, 2013 Share Posted November 22, 2013 (edited) You could try reading the file into an array with file(): http://www.php.net/file You could then use in_array() to check if the code exists: http://www.php.net/in_array Edited November 22, 2013 by cyberRobot Quote Link to comment https://forums.phpfreaks.com/topic/284162-redirect-or-error-if-the-code-doesnt-exist-in-codetxt/#findComment-1459531 Share on other sites More sharing options...
FocuSoft Posted November 22, 2013 Author Share Posted November 22, 2013 Can you give me an example please ? Quote Link to comment https://forums.phpfreaks.com/topic/284162-redirect-or-error-if-the-code-doesnt-exist-in-codetxt/#findComment-1459533 Share on other sites More sharing options...
JIXO Posted November 22, 2013 Share Posted November 22, 2013 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. Anyway, it really depends on how you format your "code.txt". Quote Link to comment https://forums.phpfreaks.com/topic/284162-redirect-or-error-if-the-code-doesnt-exist-in-codetxt/#findComment-1459536 Share on other sites More sharing options...
cyberRobot Posted November 22, 2013 Share Posted November 22, 2013 (edited) Can you give me an example please ? The links for both file() and in_array() provide examples. You just need to put the pieces together. Edited November 22, 2013 by cyberRobot Quote Link to comment https://forums.phpfreaks.com/topic/284162-redirect-or-error-if-the-code-doesnt-exist-in-codetxt/#findComment-1459537 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.