recuperer l'info avec session

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 : recuperer l'info avec session

par scorpion » 25 avr. 2007, 11:59

merci beaucoup ryle j'essaye sa :wink:

par Ryle » 25 avr. 2007, 11:49

Et bien ton nom de domaine est stocké dans ta variable $this->compl_domain

Tu peux donc soit le coller en session :
session_start();
...
$_SESSION['domaine'] = $this->compl_domain;
Le passer dans l'url (en get) :
$this->msg = "<img src='valider.jpg'> Le nom de domaine: <b>".$this->compl_domain."</b>"
  . "<font color='#008000'>est disponible</font>.<br>"
  . "<form action='commander_domaine.php?domaine=".$this->compl_domain."' method='post'>"
  . "<input src='commander.jpg' type='submit'>"
  . "</form>";

Le passer en champ hidden (en post) :
$this->msg = "<img src='valider.jpg'> Le nom de domaine: <b>".$this->compl_domain."</b>"
  . "<font color='#008000'>est disponible</font>.<br>"
  . "<form action='commander_domaine.php' method='post'>"
  . "<input type='hidden' name='domaine' value='".$this->compl_domain."' />"
  . "<input src='commander.jpg' type='submit'>"
  . "</form>";

Et selon tu n'as plus qu'à récupérer le paramètre que j'ai nommé "domaine" sur ta page 'commander_domaine.php' comme décrit plus haut, en fonction de la méthode choisie ($_SESSION, $_GET ou $_POST) :)

par scorpion » 25 avr. 2007, 11:36

merci pour ta reponse, comment je peut savoir le nom du champ en sachant que ce bout de code dit le nom de domaine libre
$this->msg = "<img src='valider.jpg'> Le nom de domaine: <b>".$this->compl_domain."</b> <font color='#008000'>est disponible</font>.<br><form action='commander_domaine.php' method='post'><input src='commander.jpg' type='submit'></form>";

par Ryle » 25 avr. 2007, 10:18

Tout dépend de la façon dont le paramètre est passé. Si c'est en GET (via l'url) il te suffit de faire appel au tableau indexé $_GET et de récupérer la valeur associé à l'index correspondant au nom de ton champ :
$valeur = $_GET['nom_du_champ'];
De même avec $_POST pour récupérer les données transmises en post, ou $_SESSION pour celles stockées en session.

Tu peux également ajouter un test pour êter sur la valeur est bien définie avant de l'utiliser :
$valeur = (isSet($_GET['nom_du_champ']) ? $_GET['nom_du_champ'] : 'valeur_par_défaut';

recuperer l'info avec session

par scorpion » 25 avr. 2007, 02:41

Bonsoir ,

J'aurai voulu savoir comment recuperer une info d'un formulaire pour qu'il me l'affiche sur la seconde page, je m'explique j'ai un script whois en php pour dire si le nom de domaine et libre ou pas.

Une fois le whois fait par exemple le nom de domaine www.essai.com et libre je voudrait que la personne qui clique sur commander que le nom de domaine s'affiche dans le formulaire.

je ne sais pas si c'est bon j'ai commencer a mettre en haut de ma page
<?php
session_start();
?>
Ensuite je bloque j'ai deja vu sur un site l'url

http://xxxxx.com/commander_domaine.php?domaine=essai&ext=fr

Se qui et en gras le nom de domaine qui et libre.

Je ne sais pas si j'explique bien j'essaye de faire de mon mieux je suis qu'un noob :)

je vous montre le code whois au cas ou vous en aurez besoin
<?php

class Whois_domain {
	
	var $possible_tlds;
	var $whois_server;
	var $free_string;
	var $whois_param;
	var $domain;
	var $tld;
	var $compl_domain;
	var $full_info;
	var $msg;
	var $info;
	var $os_system = "linux"; // switch between "linux" and "win"
	 
	function Whois_domain() {
		$this->info = "";
		$this->msg = "";
	}
	function process() {
		if ($this->create_domain()) {
			if ($this->full_info == "yes") {
				$this->get_domain_info();
			} else {
				if ($this->check_only() == 1) {
					$this->msg = "<img src='valider.jpg'> Le nom de domaine: <b>".$this->compl_domain."</b> <font color='#008000'>est disponible</font>.<br><form action='commander_domaine.php' method='post'><input src='commander.jpg' type='submit'></form>";
					return true;
				} elseif ($this->check_only() == 0) {
					$this->msg = "<img src='erreur.jpg'> Le nom de domaine: <b>".$this->compl_domain."</b> <font color='#FF0000'>est indisponible</font>.";
					return false;
				} else {
					$this->msg = "There was something wrong, try it again.";
				}
			}
		} else {
			$this->msg = "Only letters, numbers and hyphens (-) are valid!";
		}
	}
	function check_entry() {
		if (preg_match("/^([a-z0-9]+(\-?[a-z0-9]*)){2,63}$/i", $this->domain)) {
			return true;
		} else {
			return false;
		}
	}
	function create_tld_select() {
		$menu = "<select name=\"tld\" style=\"margin-left:0;\">\n";
		foreach ($this->possible_tlds as $val) {
			$menu .= "  <option value=\"".$val."\"";
			$menu .= (isset($_POST['tld']) && $_POST['tld'] == $val) ? " selected=\"selected\">" : ">";
			$menu .= $val."</option>\n";
		}
		$menu .= "</select>\n";
		return $menu;
	}
	function create_domain() {
		if ($this->check_entry()) {
			$this->domain = strtolower($this->domain);
			$this->compl_domain = $this->domain.".".$this->tld;
			return true;
		} else {
			return false;
		}
	}
	function check_only() {
		$data = $this->get_whois_data();
		if (is_array($data)) {
			$found = 0;
			foreach ($data as $val) {
				if (eregi($this->free_string, $val)) {
					$found = 1;
				} 
			}
			return $found;
		} else {
			$this->msg = "Error, please try it again.";
		}
	}
	function get_domain_info() {
		if ($this->create_domain()) {
			$data = ($this->tld == "nl") ? $this->get_whois_data(true) : $this->get_whois_data();
			if (is_array($data)) {
				foreach ($data as $val) {
					if (eregi($this->free_string, $val)) {
						$this->msg = "Le nom de domaine: <b>".$this->compl_domain."</b> is free.";
						$this->info = "";
						break;
					}
					$this->info .= $val;
				}
			} else {
				$this->msg = "Error, please try it again.";
			}
		} else {
			$this->msg = "Only letters, numbers and hyphens (-) are valid!";
		}
	}
	function get_whois_data($empty_param = false) { 
	// the parameter is new since version 1.20 and is used for .nl (dutch) domains only
		if ($empty_param) {
			$this->whois_param = "";
		}
		if ($this->tld == "de") $this->os_system = "win"; // this tld must be queried with fsock otherwise it will not work
		if ($this->os_system == "win") {
			$connection = @fsockopen($this->whois_server, 43);
			if (!$connection) {
				unset($connection);
				$this->msg = "Can't connect to the server!";
				return;
			} else {
				sleep(2);
				fputs($connection, $this->whois_param.$this->compl_domain."\r\n");
				while (!feof($connection)) {
					$buffer[] = fgets($connection, 4096);
				}
				fclose($connection);
			}
		} else {
			$string = "whois -h ".$this->whois_server." \"".$this->whois_param.$this->compl_domain."\""; 
			$string = str_replace (";", "", $string).";";
			exec($string, $buffer);
		}
		if (isset($buffer)) {
			//print_r($buffer);
			return $buffer;
		} else {
			$this->msg = "Can't retrieve data from the server!";
		}
	}
}
?>
Merci a vous ;)