Fristii
Legacy Member
Loha
Zit met een probleemke betreffende een redirect.
Even een kleine omschrijving:
Heb men frontpage (index.php) met daarop een html form, ik roep dan een php scriptje aan om men input te validaten en indien correct naar men database te schrijven. Indien de input niet correct is dient hij weer te geven wat er niet correct is. Dit lukt allemaal.
Het probleem zit em hier: Als alle input correct is, dan zou de nieuwe gebruiker automatisch naar een volgende pagina moeten doorverwezen worden. Nu weet ik dat ge moet zien dat ge niks (inclusief html tags) moogt outputten als ge nen header redirect wilt gebruiken, maar hoe kan ik een gebruiker dan op een proper gecode manier doorverwijzen naar een volgende pagina?
index.html:
input_validation.php
Zit met een probleemke betreffende een redirect.
Even een kleine omschrijving:
Heb men frontpage (index.php) met daarop een html form, ik roep dan een php scriptje aan om men input te validaten en indien correct naar men database te schrijven. Indien de input niet correct is dient hij weer te geven wat er niet correct is. Dit lukt allemaal.
Het probleem zit em hier: Als alle input correct is, dan zou de nieuwe gebruiker automatisch naar een volgende pagina moeten doorverwezen worden. Nu weet ik dat ge moet zien dat ge niks (inclusief html tags) moogt outputten als ge nen header redirect wilt gebruiken, maar hoe kan ik een gebruiker dan op een proper gecode manier doorverwijzen naar een volgende pagina?
index.html:
HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="frontpage.css" />
<title>OWL: An Online Whishlist Managing System</title>
</head>
<body>
<?php include("input_validation.php"); ?>
<div class="container">
<div class="header">
<div style="float:left;padding:0;margin:0; height:100%">
<h1 style="font-family:sans-serif;color:white; padding-top:20px; padding-left:20px; margin-top:0; font-size:3em">OWL</h1>
</div>
<div class="login" style="float:right; padding-top:20px;">
<form>
<label style="font-size:0.75em" for="rememberMe">Remember Me?</label>
<input style="margin-right:75px" type="checkbox" id="remberMe" name="Remember Me" value="Remember Me" />
<a style="font-size:0.75em; color:orange; margin-right:100px" href="passLost.php">Forgot your password?</a>
<br />
<input type="text" id="userName" name ="username" />
<input type="password" id="pass" name = "password" />
<input type="submit" value="logIn" />
</form>
</div>
</div>
<div class="bodycont">
<div class="contents">
<h2>Sign Up!</h2>
<h3>It's Free, so why not join now?</h3>
<div class="form">
<form name="registerInput" action='<?php $_SERVER[PHP_SELF] ?>' method="post">
<label for="fName">First Name:</label>
<input id="fName" name="fName" type="text" value="First Name..." maxlength="25">
<br />
<label for="lName">Last Name:</label>
<input id="lName" name="lName" type="text" value="Last Name..." maxlength="75">
<br />
<label for="eMail">Email:</label>
<input id="eMail" name="eMail" type="text" value="E-mail..." maxlength="75">
<br />
<label for="pWord">Password:</label>
<input id="pWord" name="pWord" type="password" value="" maxlength="16">
<br />
<label for="uName">Username:</label>
<input id="uName" name="uName" type="text" value="" maxlength="12">
<br />
<input type="submit" value="Sign Up" style="margin-right:110px" />
<?php validate(); ?>
</form>
</div>
</div>
<div class="body">
<h1 class="contents">OWL let's you create, manage and share whishlists!</h1>
<img src="https://www.beyondgaming.be/forums" />
</div>
</div>
<div class="footer">
<hr />
<div style="float:left;">
<p class="footer">Kevin Wyckmans © 2009</p>
</div>
<div style="float:right; padding:0; ; margin:-0.5% 5% 0 0">
<a href="about.php" style="padding:0; padding-right:10px">About</a>
<a href="mailto:[email protected]?subject=Test" style="padding:0">Contact me</a>
</div>
</div>
</div>
</body>
</html>
input_validation.php
PHP:
<?php
require("email_validation.php");
$valid = TRUE;
function validate(){
global $valid;
if(checkSet() != FALSE)
{
if(empty($_POST['fName'])==FALSE && sanityCheck($_POST['fName'], 'string', 25))
{
$fName = $_POST['fName'];
}
else
{
$valid = FALSE;
echo '<p style="color:red">Please enter a correct first name</p>';
/*exit();*/
}
if(empty($_POST['lName'])==FALSE && sanityCheck($_POST['lName'], 'string', 75))
{
$lName = $_POST['lName'];
}
else
{
$valid = FALSE;
echo '<p style="color:red">Please enter a correct last name</p>';
/*exit();*/
}
if(empty($_POST['eMail'])==FALSE && sanityCheck($_POST['eMail'], 'string', 75) && checkmail($_POST['eMail']))
{
$eMail = $_POST['eMail'];
}
else
{
$valid = FALSE;
echo '<p style="color:red">Please enter a correct e-mail address</p>';
/*exit();*/
}
if(empty($_POST['pWord'])==FALSE && sanityCheck($_POST['pWord'], 'string', 16))
{
$pWord = sha1( $_POST['pWord']);
}
else
{
$valid = FALSE;
echo '<p style="color:red">Please enter a password</p>';
}
if(empty($_POST['uName']) == FALSE && sanityCheck($_POST['uName'], 'string', 12))
{
$uName = $_POST['uName'];
}
else{
$valid = FALSE;
echo '<p style="color:red">Please enter a correct username</p>';
}
if($valid == TRUE)
{
$dsn = 'mysql:dbname=Owl;host=127.0.0.1';
$user = 'fristi';
$password = '';
try{
$dbh = new PDO($dsn, $user, $password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
$sql = "INSERT INTO gebruiker (id, vNaam, aNaam, eMail, geboorteDatum, pFoto, pass,uNaam) VALUES ('0',' $fName',' $lName', '$eMail', NULL, NULL,
'$pWord', '$uName')";
$dbh->query($sql);
$dbh = null;
}
catch(PDOException $e){
if($dbh->errorCode() == '23000')
{
echo '<p style="color:red"> A user with that username already exists</p>';
}
}
}
}
}
function redirect(){
global $valid;
if(valid){
header( 'Location: http://127.0.0.1/dashboard.php' );
}
}
/**
* This function can be used to check the sanity of variables
*
* @access private
*
* @param string $type The type of variable can be bool, float, numeric, string, array, or object
* @param string $string The variable name you would like to check
* @param string $length The maximum length of the variable
*
* return bool
*/
function sanityCheck($string, $type, $length){
// We kennen het type toe om dit iets verderop te kunnen controleren met ingebouwde functies
$type = 'is_'.$type;
//We controleren of onze string van het welbepaalde type is
if(!$type($string)){
return FALSE;
}
elseif(empty($string)){
return FALSE;
}
elseif(strlen($string) > $length){
return FALSE;
}
else{
//De gegevens zijn alvast van het goeie type en niet te lang of leeg
return TRUE;
}
}
function checkSet(){
return isset($_POST['fName'], $_POST['lName'], $_POST['eMail'], $_POST['pWord']);
}
?>
