Mikey3523 Posted June 19, 2008 Share Posted June 19, 2008 Hello, I'm making a code where someone who types in a certain word, gets taken to another page which gives them a kind of 'clue' to something. What I was wondering is, where about in a php code would the part be where the forum recognises someone is using that specific word? How would it look and any tips on how to set it up? If someone could give me any help it would be much appreciated! Thanks in advance! Mikey Quote Link to comment Share on other sites More sharing options...
MadnessRed Posted June 19, 2008 Share Posted June 19, 2008 can you make yourself a bit more clear please If you are trying to do what i think you are I would set up a form and use the "get" to include a page, 1 sec and Ill write a code in example Quote Link to comment Share on other sites More sharing options...
Stephen Posted June 19, 2008 Share Posted June 19, 2008 After you make a form, you do something like this: <?php if ($_POST["inputname"]=="word") { header("Location: page.php"); } else { echo("Failed the word."); } ?> Quote Link to comment Share on other sites More sharing options...
MadnessRed Posted June 19, 2008 Share Posted June 19, 2008 kk, lol my code would allow multiple codes, each with a file of there own, but if you only have 1 then use the code above on the page <form action="secret.php" method="post"> Enter Code: <input name="code" type="text" /> <input type="submit" value="Upload" /> </form> secret.php <? php $code = $_POST["code"]; $page = $code.'.php'; if (file_exists($page)) { include '$page'; } else { include 'invalidcode.php'; } ?> Then for code "elephant" you would make a page "elephant.php", for code "frog" you would make a page "from.php" If you want the codepages to be html then change $page = $code.'.php'; to $page = $code.'.html'; Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 19, 2008 Share Posted June 19, 2008 Except that's not secure, MadnessRed. =/ Quote Link to comment Share on other sites More sharing options...
Mikey3523 Posted June 19, 2008 Author Share Posted June 19, 2008 A form? Do you mean a posting form? If so, I already have one of them. I'm not sure what you mean by only using one code. Basically, I want to set up a code which takes users to a different page when they type this specific word. Which code would I use for this out of the three you posted? Thanks for helping aswell guys! Quote Link to comment Share on other sites More sharing options...
MadnessRed Posted June 19, 2008 Share Posted June 19, 2008 How about this then? secret.php <? php $code = $_POST["code"]; $page = $code.'.php'; if (file_exists($page)) { header("Location: ". $page); } else { echo("Incorrect code"); } ?> Quote Link to comment Share on other sites More sharing options...
MadnessRed Posted June 19, 2008 Share Posted June 19, 2008 how many codes will you have? If you have more than 1 code then use the code that i gave If you only have 1 code then you the code that the Stephen said Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 19, 2008 Share Posted June 19, 2008 Yeah, use Stephen's if it's one word. If it's more, make an array and use in_array(). @MadnessRed: It's not secure, because what if their word was ../somefile? Then they're at ../somefile.php. You can't just "make sure the file exists and then send them there." Quote Link to comment Share on other sites More sharing options...
MadnessRed Posted June 19, 2008 Share Posted June 19, 2008 urm, why not? or how about... make secret.php secret/index.php then put the code files in there. Quote Link to comment Share on other sites More sharing options...
Mikey3523 Posted June 19, 2008 Author Share Posted June 19, 2008 Okay thanks guys! Where Stephen has put 'Failed the word' what would I put there? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 19, 2008 Share Posted June 19, 2008 You'd put what you want it to display if there word wasn't correct. Quote Link to comment Share on other sites More sharing options...
Mikey3523 Posted June 19, 2008 Author Share Posted June 19, 2008 Oh but if there word isn't correct, I dont want anything to show. Basically, it's just a normal post but if someone happens to use this word in any of their posts, they get taken to a page. I only want the forum to notice it if a user includes this word in their post. If they don't, then I just want things to carry on as normal. The users dont know this will be set up so it's kind of a surprise Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 19, 2008 Share Posted June 19, 2008 That's completely different than what you said in the original post. You'll need to use strpos to see if it's in there. You'll need to add spaces to both ends of the word too, to make sure they don't have a word inside of a word. Quote Link to comment Share on other sites More sharing options...
Mikey3523 Posted June 19, 2008 Author Share Posted June 19, 2008 So does this mean Stephens code is out of the picture now or can It still be used but with a bit of modification? Thanks for helping too! Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 19, 2008 Share Posted June 19, 2008 1) His will suffice with a modification or two. Can you do it on your own? 2) Why in the world did you type that in a bright pink color? D: I needed to highlight it to read it properly. Quote Link to comment Share on other sites More sharing options...
Stephen Posted June 19, 2008 Share Posted June 19, 2008 If you don't want anything to happen after it checks the word you can just remove the else. Quote Link to comment Share on other sites More sharing options...
Mikey3523 Posted June 19, 2008 Author Share Posted June 19, 2008 Sorry I pressed the wrong color and realised that may be hard to read... So does this mean Stephens code is out of the picture now or can It still be used but with a bit of modification? Thanks for helping too! Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 19, 2008 Share Posted June 19, 2008 <?php if (strpos($_POST['post'], " word ") !== FALSE) { header("Location: page.php"); exit; } ?> Make sure to do that AFTER you put their post into the database, so they don't need to retype it. Quote Link to comment Share on other sites More sharing options...
Mikey3523 Posted June 19, 2008 Author Share Posted June 19, 2008 What do you mean by after I've put their code in the database? So that code you just provided me with...if I use that, will it make it so that if this word is typed, they will be taken to the page I direct it to? Also, how do I donate? You've been a big help so if I solve this, I think I'll help out Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 19, 2008 Share Posted June 19, 2008 You can donate to me via Paypal. I'll PM you my PayPal e-mail if you want. I mean that you don't want to redirect them before their post goes into the database. You said this was a forum, right? So therefore, you should place this AFTER the post is placed into the database. Quote Link to comment Share on other sites More sharing options...
Mikey3523 Posted June 19, 2008 Author Share Posted June 19, 2008 Yeah it's a forum but when you say after their post is placed into the database, where about should I put this code? I wont be able to be on 24 hours a day when everyone makes posts... I might just be reading this wrong though lol. So where about would I put this code? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 19, 2008 Share Posted June 19, 2008 Put it inside the script, but place it AFTER the code that does the post insertion. I.E: <?php include ('somefile.php'); //example includes or w/e. /************************* *Here is where you insert it into the database **************************/ //Here's where the redirection code goes ?> Quote Link to comment 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.