Jump to content

non-database php form stuffs


anoveskey

Recommended Posts

Hello!

 

I am attempting to put together a little 'login' of sorts, where a user inputs 4 numeric values into a form. The values are then compared to variables in a php script to see if the input matches. If the input matches, the php script should redirect to a new page. Problem is, when I hit the 'submit' button, the script itself is brought up, rather than a redirect. I'm trying to keep the values in the php script hidden as well so the user can't just ctrl+u and see what the script looks like. Any suggestions?

 

Here is my form:

<!-- Input Form -->
<div>
	<form id="inputForm" name="inputForm" method="POST" action="code-login.php">
		<p>Grab some coffee:		
		<input type="text" name="input1" size="2" />
		<input type="text" name="input2" size="2" />
		<input type="text" name="input3" size="2" />
		<input type="text" name="input4" size="2" />
		<input type="submit" value="Crack the Code!" />
		</p>
	</form>
</div>

and here is the php script:

<?php

	$firstValue =  $_POST['input1'];
	$secondValue =  $_POST['input2'];
	$thirdValue =  $_POST['input3'];
	$fourthValue =  $_POST['input4'];

if ((($firstValue === '##') && ($secondValue === '##')) && (($thirdValue === '##') && ($fourthValue === '##'))) { 
	header('http://www.someotherpage.com/'); 
	exit(); }
else { echo "The code is incorrect."; }
?>

BTW, the ##'s in the if statement are strictly there as place holders. Actual numbers will take their place in the real script.

 

Thanks!

Link to comment
Share on other sites

simpler alternative

<form id="inputForm" name="inputForm" method="POST" action="code-login.php">
        <p>Grab some coffee:        
        <input type="text" name="input[]" size="2" />
        <input type="text" name="input[]" size="2" />
        <input type="text" name="input[]" size="2" />
        <input type="text" name="input[]" size="2" />
        <input type="submit" value="Crack the Code!" />
        </p>
</form>

then

<?php
    $correct = array ('##', '##', '##', '##');
    
    if (isset($_POST['input'])) {
        if ($_POST['input'] == $correct) {
            header("Location: http://www.someotherpage.com/");
            exit;
        }
        else {
            echo "Code is incorrect<br>";
        }
    }
?>
Link to comment
Share on other sites

the script itself is brought up

 

 

that would indicate that either you don't have php installed/functioning on your web server OR you opened the form as a file directly in your browser rather than browsing to the URL of your form page and it didn't actually submit to the URL of your form processing code.

Link to comment
Share on other sites

Just so you know, you can't see any php code when you view the source of a page in the browser.  All the php is server side and doesn't show client side.

 

Yeah, nothing shows up on the screen, but when you hit ctrl+u in Firefox it shows the script source.

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.