créer une redirection en fonction du sexe

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : créer une redirection en fonction du sexe

par webide » 23 juil. 2009, 07:57

J'ais fait comme cela le fichier register.php
<?php

	/* Check Structure Availability */
	if (!defined("CORE_STRAP")) die("Out of structure call");
	

	$tpl = new template;
	$tpl -> Load("register");
	
		/* genre */
		if ($_SESSION["REGISTER"]["gender"]=="male") {
    		header('Location:page_mec.php');
			}
			else if ($_SESSION["REGISTER"]["gender"]=="cpl") {
     		header('Location:page_cpl.php');
			}
			else {
     		header('Location:page_fille.php');


	}
		$tpl -> CleanZones();
		$tpl -> Flush();
	
?>
et sur le fichier tpl couplé (register.tpl) avec ce fichier php

Code : Tout sélectionner

<!-- header --><!-- /header --> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="530">&nbsp;</td> <td rowspan="2">&nbsp;</td> <td width="290">&nbsp;</td> </tr> <tr> <td width="530" valign="top"><!-- leftpane --><form method="post"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="25">&nbsp;</td> <td><h1>[Register {50}] </h1> <p>[Welcome! {7510}] &nbsp; </p> <p>&nbsp;</p> <p>[Let's get started! {7515}] </p> <p>&nbsp;</p><!-- breadcrumbs --><!-- /breadcrumbs --> </td> </tr> <tr> <td>&nbsp;</td> <td>&nbsp;</td> </tr> <tr> <td height="8" colspan="2"><img src="theme/default/images/frame/spacer.gif" alt="Spacer" height="8" /></td> </tr> <tr> <td colspan="2" background="theme/default/images/frame/block_border_top.gif" bgcolor="#AEC5FD"><img src="theme/default/images/frame/spacer.gif" alt="Spacer" height="14" /></td> </tr> <tr> <td bgcolor="#DCE6FF">&nbsp;</td> <td bgcolor="#DCE6FF">&nbsp;</td> </tr> <tr> <td bgcolor="#DCE6FF">&nbsp;</td> <td bgcolor="#DCE6FF"><h2>[Please complete the following {7520}] </h2></td> </tr> <tr> <td width="150" align="right" valign="top"><strong>[I Am A: {7550}]</strong> </td> <td align="left" valign="top"><select name="gender" id="gender"> <LOOP genderoption> <option value="{gender}">{gender}</option> </LOOP genderoption> </select></td> </tr> </table><!-- /rightpane --></td> </tr> </table> <!-- footer --><!-- /footer -->
La redirection s'effectue immédiatement et m'envoie sur la page page_fille.php .
Comment puis je faire pour que seuleument après avoir selectionné mon genre je suis redirigé vers la page souhaitée

par djutopie » 22 juil. 2009, 20:08

if ($_SESSION["REGISTER"]["gender"]=="male") { 
     header('Location:page_mec.php'); 
} 
else if ($_SESSION["REGISTER"]["gender"]=="cpl") { 
     header('Location:page_cpl.php'); 
} 
else { 
     header('Location:page_fille.php'); 
} 
Ton code est sensé marcher mais c plus "propre" comme ca.

"else if" au lieu de "else", mais tu devrais voir les bases de la programmation
avant de te lancer a l'emporte pièce dans la création d'un site :

http://www.phpdebutant.org/

++

par webide » 22 juil. 2009, 20:00

Ok merci juste une dernière petite question si je veut rajouter un choix je dois alors faire:
if ($_SESSION["REGISTER"]["gender"]=="male") { 
     header('Location:page_mec.php'); 
} 
if ($_SESSION["REGISTER"]["gender"]=="cpl") { 
     header('Location:page_cpl.php'); 
} 
else { 
     header('Location:page_fille.php'); 
} 

Et merci beaucoup pour l'aide

par Ryle » 22 juil. 2009, 19:01

Utilises plutôt la fonction header() pour faire la redirection côté serveur, au lieu de la faire en javascript (qui pourrait dépendre du paramétrage, du navigateur...)
if ($_SESSION["REGISTER"]["gender"]=="male") { 
     header('Location:page_mec.php'); 
} 
else { 
     header('Location:page_fille.php'); 
} 

par webide » 22 juil. 2009, 18:56

Merci beaucoup, c'est comme cela que je l'imaginais car il y a 2 étapes à l'enregistrement (celle ci ou l'on valides les informations personnelles et un questionnaire).

par djutopie » 22 juil. 2009, 18:45

Code : Tout sélectionner

if ($_SESSION["REGISTER"]["gender"]=="male") { echo "<script langage=javascript>document.location='page_mec.php'</script>"; } else { echo "<script langage=javascript>document.location='page_fille.php'</script>"; }

par Stef » 22 juil. 2009, 18:13

hello,

à quel moment tu veux faire ta redirection? après l'enregistrement dans ta base de données ou avant?

par webide » 22 juil. 2009, 18:01

le seul endroit ou apparait cette ligne se trouve au niveau des données de la base

Code : Tout sélectionner

/* Save to database */ myQ(" INSERT INTO `[x]users` ( `email`, `birthdate`, `gender`, `username`, `password`, `country`, `state`, `city`, `zipcode`, `active`, `registration_date`, `registration_reference`, `age`, `settings` ) VALUES ( '{$_SESSION["REGISTER"]["email"]}', '{$_SESSION["REGISTER"]["bmonth"]}/{$_SESSION["REGISTER"]["bday"]}/{$_SESSION["REGISTER"]["byear"]}', '{$_SESSION["REGISTER"]["gender"]}', '{$_SESSION["REGISTER"]["username"]}', '".md5($_SESSION["REGISTER"]["password"])."', '{$_SESSION["REGISTER"]["country"]}', '{$_SESSION["REGISTER"]["state"]}', '{$_SESSION["REGISTER"]["city"]}', '{$_SESSION["REGISTER"]["zipcode"]}', '".($CONF["REGISTRATION_AUTO_APPROVE"] && !$CONF["REGISTRATION_APPROVE_UPON_EMAIL_CHECK"]?"1":"0")."', '".date("U")."', '{$refData}', '"._fnc("age", "{$_SESSION["REGISTER"]["bmonth"]}/{$_SESSION["REGISTER"]["bday"]}/{$_SESSION["REGISTER"]["byear"]}")."', '".pk($user_settings)."' ) ");
et nulle part ailleurs et étant novice en la matière, je ne vois pas trop comment faire[/code]

par djutopie » 22 juil. 2009, 17:36

Salut,

ici je vois :

Code : Tout sélectionner

myQ(" INSERT INTO `[x]users` ( `email`, `birthdate`, [b]`gender`[/b], `username`, `password`, `country`, `state`, `city`, `zipcode`, `active`, `registration_date`, `registration_reference`, `age`, `settings` )
Quand tu inscrit le membre ya bien la valeur gender qui est le sexe.
Suffit que tu fasse une requete SELECT SQL pour obtenir sa valeur et ainsi rediriger comme tu le voulais.

++

créer une redirection en fonction du sexe

par webide » 22 juil. 2009, 16:07

Bonjour,
Je souhaiterais créer deux redirections différentes en fonction du sexe de la personne. J'utilises un script fonctionnant sur 2 fichier.
Il y a le fichier php gérant l'inscription
if (me('id') != "") {
		$tpl -> Zone("regform", "notallowed");
		_fnc("reload", 3, "?L=users.desktop");
	}
	
	if (isset($_SESSION["REG_ID"])) {
		$tpl -> Zone("regform", "notallowed");
		_fnc("reload", 0, "?L=registration.questionaire");
	}

	/* Handle Submit */
	if (isset($_POST["Submit"]) || isset($_POST["Correct"])) {
		
		$errBreak = false;
		
		foreach ($_POST as $var => $val) {
			$_SESSION["REGISTER"][$var] = $val;
		}
		
		/* Check email address */
		if (
			!isset($_SESSION["REGISTER"]["email"]) 
			|| $_SESSION["REGISTER"]["email"] == "" 
			|| !preg_match($CONF["REGEXP_EMAIL"], $_SESSION["REGISTER"]["email"])) {
			$tpl -> Zone("error", "email");
		} else {
			/* Check Cloned email addresses */
			if (!$CONF["REGISTRATION_ALLOW_DUPLICATE_EMAIL"] && myNum(myQ("
				SELECT `email` 
				FROM `[x]users` 
				WHERE `email`='{$_SESSION["REGISTER"]["email"]}'
			")) > 0) {
				$tpl -> Zone("error", "emailClone");
				session_unregister("REGISTER");
			} 
			
			else {
				/* Check username */
				if (
					!isset($_SESSION["REGISTER"]["username"]) 
					|| $_SESSION["REGISTER"]["username"] == "" || 
					!preg_match($CONF["REGEXP_USERNAME"], $_SESSION["REGISTER"]["username"])
					|| strlen($_SESSION["REGISTER"]["username"]) < $CONF["USERS_USERNAME_MIN_LEN"]
					|| strlen($_SESSION["REGISTER"]["username"]) > $CONF["USERS_USERNAME_MAX_LEN"]) {
					$tpl -> Zone("error", "username");
					$tpl -> Zone("usernameerror", "lenerror");
				}
				
				else {
					/* Check username being in use */
					if (myNum(myQ("
						SELECT `username` 
						FROM `[x]users` 
						WHERE LCASE(`username`)='".strtolower($_SESSION["REGISTER"]["username"])."'")) > 0) {
						$tpl -> Zone("error", "username");
						$tpl -> Zone("usernameerror", "inuse");
					} else {
						/* Check Password form */
						if (
							!isset($_SESSION["REGISTER"]["password"]) 
							|| $_SESSION["REGISTER"]["password"] == "" 
							|| strlen($_SESSION["REGISTER"]["password"]) < $CONF["USERS_PASSWORD_MIN_LEN"] 
							|| strstr($_SESSION["REGISTER"]["password"], " ")) {
							$tpl -> Zone("error", "password");
							$tpl -> Zone("passworderror", "lenghterr");
						} else {
							/* Check password against passcheck */
							if (
								!isset($_SESSION["REGISTER"]["passcheck"]) 
								|| $_SESSION["REGISTER"]["passcheck"] != $_SESSION["REGISTER"]["password"]) {
								$tpl -> Zone("error", "password");
								$tpl -> Zone("passworderror", "nomatch");
							} else {
								/* Check verification code */
								if (
									!isset($_SESSION["REGISTER"]["code"]) || 
									!isset($_SESSION["REGISTER"]["syscode"]) || 
									$_SESSION["REGISTER"]["code"] != $_SESSION["REGISTER"]["syscode"]) {
									$tpl -> Zone("error", "code");
								} else {
									/* Check age */
									if (
										!isset($_SESSION["REGISTER"]["bday"]) or
										!isset($_SESSION["REGISTER"]["bmonth"]) or
										!isset($_SESSION["REGISTER"]["byear"]) or
										_fnc("age", $_SESSION["REGISTER"]["bmonth"]."/".$_SESSION["REGISTER"]["bday"]."/".$_SESSION["REGISTER"]["byear"]) < $CONF["USERS_MIN_AGE"]
									) {
										$tpl -> Zone("error", "age");
									} else {
										/* Form was correctly filled */
										
										if (!isset($_SESSION["REG_ID"])) {
											
											/* Set reference data */
											if ($CONF["REGISTRATION_SAVE_REFERENCE"]) {
												if ($CONF["REGISTRATION_REFERENCE:HTTP_REFERER"]) $refData = $_SERVER['HTTP_REFERER'];
												else $refData = (isset($_GET["ref"])?$_GET["ref"]:NULL);
											} else $refData = NULL;
											
											$user_settings["MAIL"]["NOTIFICATION"] = array(
												"MESSAGES" => 1,
												"EVENTS" => 1,
												"BIRTHDAY" => 1,
												"PROFILECOMMENT" => 1,
												"CONTACTREQUEST" => 1,
												"NUDGE" => 1
											);
											
											/* Save to database */
											myQ("
												INSERT INTO `[x]users` 
												(
													`email`,
													`birthdate`,
													`gender`,
													`username`,
													`password`,
													`country`,
													`state`,
													`city`,
													`zipcode`,
													`active`,
													`registration_date`,
													`registration_reference`,
													`age`,
													`settings`
												)
												VALUES
												(
													'{$_SESSION["REGISTER"]["email"]}',
													'{$_SESSION["REGISTER"]["bmonth"]}/{$_SESSION["REGISTER"]["bday"]}/{$_SESSION["REGISTER"]["byear"]}',
													'{$_SESSION["REGISTER"]["gender"]}',
													'{$_SESSION["REGISTER"]["username"]}',
													'".md5($_SESSION["REGISTER"]["password"])."',
													'{$_SESSION["REGISTER"]["country"]}',
													'{$_SESSION["REGISTER"]["state"]}',
													'{$_SESSION["REGISTER"]["city"]}',
													'{$_SESSION["REGISTER"]["zipcode"]}',
													'".($CONF["REGISTRATION_AUTO_APPROVE"] && !$CONF["REGISTRATION_APPROVE_UPON_EMAIL_CHECK"]?"1":"0")."',
													'".date("U")."',
													'{$refData}',
													'"._fnc("age", "{$_SESSION["REGISTER"]["bmonth"]}/{$_SESSION["REGISTER"]["bday"]}/{$_SESSION["REGISTER"]["byear"]}")."',
													'".pk($user_settings)."'
												)
											");
couplé avec le fichier tpl affichant la page

Code : Tout sélectionner

<td width="150" align="right" valign="top"><strong>[I Am A: {7550}]</strong> </td> <td align="left" valign="top"><select name="gender" id="gender"> <LOOP genderoption> <option value="{gender}">{gender}</option> </LOOP genderoption> </select></td> </tr> <tr> <td width="150" align="right" valign="top"><strong>[Username: {7555}]</strong></td> <td align="left" valign="top"><input name="username" type="text" id="username" maxlength="{username_maxlen}" /> <br /> [Username must be between {username_minlen} and {username_maxlen} characters. Spaces or special characters are not allowed. Username is not case sensitive. {7560}] </td> </tr> <tr> <td width="150" align="right" valign="top"><strong>[Password: {7570}] </strong></td> <td align="left" valign="top"><input name="password" type="password" id="password" /> <br />
Seuleument voila, nulle part sur le fichier php (a part au niveau de l'enregistrement sur la base) je ne trouves de ligne de code concernant le sexe et comme dit je souhaites que lorsqu'il s'agit d'un homme il soit redirigé vers une page et une femme vers une autre page.

Merci d'avance pour vos conseils.