Page 1 sur 1

Validation Captcha pour redirection dans une page

Posté : 09 janv. 2010, 16:22
par bloodjean
Bonjour,

Je recherche quelqu'un qui pourrait m'aider à modifier un script selon certains critères.
Il s'agit d'une page où je voudrais ajouter un "captcha".
Mes connaissances étant limitées dans ce domaine et en PHP, je n'y arriverai pas tout seul. Mais, je pense que ce pourra être réalisé en moins d'une heure par un codeur de bon niveau (meilleur que le mien :wink: ). Sachant que le script contient déjà un captcha, il suffira juste de le découvrir, de comprendre ma requête et d'ajouter quelques lignes.

Merci par avance.

Bloodjean

Re: Codeur PHP/HTML

Posté : 09 janv. 2010, 16:52
par dunbar
Montre ton code sur le forum et tu y trouvera surement de l'aide gratuitement :wink:

Re: Codeur PHP/HTML

Posté : 09 janv. 2010, 17:49
par bloodjean
Je me suis dit aussi que j'aurai dû montrer les pages mais mon script est sur plusieurs pages.
C'est donc assez complexe...

Je veux créer une page qui, une fois le captcha validé, ira directement sur la page <!--=$fullurl=--> (ceci est le lien de la page).
J'ai un exemple sur une autre page, d'un formulaire contenant le captcha, du même script.

    <!-- form start -->
    <form name="fomu" action="" method="post">
    <input type=hidden name=rnd value=<!--=$rnd=--> />

    <p>Here you can create a short URL that can be effectively used instead of an existing, long URL. Enter your URL in the textbox below and click "Make Short URL!" to create a short URL.</p>

    <p>Please fill in the following field with the URL you want to shorten<br />(put a copy/past from URL):<br />
    <img src="urlinn_images/blank.gif" width="1" height="5" alt="" /><br />
    <input class="front" name="fullurl" type="text" maxlength="4096" style="width:100%;" value="<!--=if $p_fullurl =--><!--=$p_fullurl=--><!--=else=-->http://<!--=/if=-->" /></p>

    <p>Keyword (optional):<br />
    <img src="urlinn_images/blank.gif" width="1" height="5" alt="" /><br />
    <input class="front" name="keyword" type="text" maxlength="256" style="width:75%;" value="<!--=$p_keyword=-->" /></p>
    
    <!--=if $captcha =-->
    <p>Secure code:<br />
    <img src="urlinn_images/blank.gif" width="1" height="5" alt="" /><br />
    <img src="captcha.php" width="240" height="60" alt="Captcha" />
    </p>

    <p>Type secure code here (required):<br />
    <img src="urlinn_images/blank.gif" width="1" height="5" alt="" /><br />
    <input class="front" name="captcha" type="text" value="" maxlength="256" style="width:240px;" />
    </p>
    <!--=/if=-->

    <p><input class="front" type="submit" value="Make Short URL!" /></p>

    </form>
    <!-- form end -->
Et voici, la page php qui va avec :
<?php

if (!$_GET['page'] || preg_match('/\W/',$_GET['page']) || !file_exists('./urlinn_templates/'.$_GET['page'].'.htm')) $_GET['page'] = 'index';

$smarty = new Tpl;
$smarty->assign("url_to_index", $config['url_to_index']);
$smarty->assign("admin_email",  $config['admin_email']);
$smarty->assign("records",      getNumb());
$smarty->assign("captcha",      $config['captcha']);

if ($_GET['page'] && $_GET['page']!='index') {
  $smarty->assign("pg_".$_GET['page'],true);
  $smarty->display($_GET['page'].".htm");
  exit;
}
$smarty->assign("pg_index",true);

if($_REQUEST['fullurl']=='http://') $_REQUEST['fullurl'] = $_POST['fullurl'] = $_GET['fullurl'] = $fullurl = '';

if ($rnd) {
  if ($rnd==SessionGet('rand')) {
    unset($_POST);
    unset($_GET);
    unset($_REQUEST);
  }
  else {
    SessionSet('rand',$rnd);
  }
}

if ($_POST['email'] && $_GET['act']=='send_mail' && IsEmail($_POST['email']) && is_numeric($_POST['id'])) {
  $headers = 'From: '.$_POST['email_from']."\r\n" .
    'Reply-To: '.$_POST['email_from']."\r\n" .
    'X-Mailer: PHP/'.phpversion();

  if (preg_match('/\W/',$_POST['randlink'])) $_POST['randlink'] = '';
  $query1 = "UPDATE urlinn_websites SET email='{$_POST['email']}' WHERE wid='{$_POST['id']}' AND tinylink='{$_POST['randlink']}'";
  $result1 = $myDB->Execute($query1) or die(GetDbError($myDB->ErrorMsg()));

  if ($myDB->Affected_Rows()) {
    mail($_POST['email'], $_POST['email_subj'], $_POST['email_body'], $headers);
    $smarty->assign("email_sent",1);
  }
  $smarty->display("index.htm");
  exit;
}
elseif (!$_POST && $_GET['act']=='stats') {
  $_GET['id'] = (int) $_GET['id'];
  if (preg_match('/\W/',$_GET['secret_code'])) $_GET['secret_code'] = '';
  $query1 = "SELECT * FROM urlinn_websites WHERE wid='{$_GET['id']}' AND secret_code='{$_GET['secret_code']}'";
  $result1 = $myDB->Execute($query1) or die(GetDbError($myDB->ErrorMsg()));
  $wid = $result1->Fields("wid");
  if (!$wid) die("<code>Access denied! Wrong ID or Secure Code..</code>");
  $smarty->assign("wid", $wid);
  $fullurl = $result1->Fields("fullurl");
  $smarty->assign("fullurl",        $fullurl);
  $smarty->assign("fullurl_substr", ((strlen($fullurl)>75)?substr($fullurl,0,75).'...':$fullurl));
  $smarty->assign("ip",             $result1->Fields("ip"));
  $smarty->assign("tinylink",       $result1->Fields("tinylink"));
  $smarty->assign("email",          $result1->Fields("email"));
  $smarty->assign("total",          getUserTotal());
  $smarty->display("stats.htm");
  exit;
}

SessionDelete('searchurl');
$randlink = '';

if ($_GET['QUERY_STRING']) $_SERVER['QUERY_STRING'] = $_GET['QUERY_STRING'];

if ($_SERVER['QUERY_STRING'] && !$_REQUEST['fullurl'] && !preg_match('/[^\w\-]/',$_SERVER['QUERY_STRING'])) {
  //loading index.php with query
  if (isBlockedKeyword($_SERVER['QUERY_STRING'])) {
    //query blocked
    $smarty->assign("ad", GetRandomAd());
    $smarty->display("error.htm");
  }
  elseif($res = checkQueryString($_SERVER['QUERY_STRING'])){
    //query found
    if ($config['hide_real_url']) {
      $smarty->assign("real_url", $res['fullurl']);
      $smarty->display("frame.htm");
    }
    elseif ($res['showsplash'] && $config['refreshrate']) {
      $smarty->assign("fullurl",        $res['fullurl']);
      $smarty->assign("fullurl_substr", (strlen($res['fullurl'])>75?substr($res['fullurl'],0,75).'...':$res['fullurl']));
      $smarty->assign("refreshrate",    $config['refreshrate']);
      $smarty->assign("connect_page",   1);
      $smarty->assign("ad",             GetRandomAd());
      $smarty->display("connect.htm");
    }
    else redirect($res['fullurl']);
  }
  else{
    //query did not fount
    $smarty->assign("ad", GetRandomAd());
    $smarty->display("error.htm");
  }
}
else {

  $err_msg = '';
  if ($_REQUEST['fullurl']) {

    require_once "./urlinn_includes/i_Captcha.php";
    $captcha = new Captcha();
    if ($config['captcha'] && !$captcha->check($_POST['captcha'])) {
      $err_msg = 'Sorry, secure code you entered is not valid.\nTry again please.';
      $smarty->assign("p_fullurl", $_REQUEST['fullurl']);
      $smarty->assign("p_keyword", $_POST['keyword']);
    }
    else {
      $ip = '';
      $err_msg = isValidFullURL($_REQUEST['fullurl'],$ip);
    }

    // everything is ok..
    if (!$err_msg) {
      list($randlink,$lastid,$secret_code) = addLink($_REQUEST['fullurl'],$ip);
    }
    else {
      js_alert($err_msg);
    }

    $smarty->assign("records", getNumb());
  }

  //loading index.php
  $smarty->assign("fullurl",         $_REQUEST['fullurl']);
  $smarty->assign("fullurl_substr",  ((strlen($_REQUEST['fullurl'])>75)?substr($_REQUEST['fullurl'],0,75).'...':$_REQUEST['fullurl']));
  $smarty->assign("randlink",        $randlink);
  $smarty->assign("fullrand",        $config['url_to_index'].$config['mod_rewrite_char'].$randlink);
  $smarty->assign("secret_code",     $secret_code);

  $smarty->assign("id",              $lastid);
  $smarty->assign("fullurl_length",  strlen($_REQUEST['fullurl']));
  $smarty->assign("randlink_length", strlen($config['url_to_index'].$config['mod_rewrite_char'].$randlink));

  $smarty->assign("rnd",             mt_rand());
  $smarty->display("index.htm");
}

?>

Re: Validation Captcha pour redirection dans une page

Posté : 09 janv. 2010, 20:36
par dunbar
Tu crée une variable de session
$_SESSION['captcha'] = $_POST['capctha'];
Puis il te suffit de faire un test pour vérifier le code entrée
$Capctha = ((iSset($_POST['capctha']) &&($_POSt['capctha'] == $_SESSION['capctha'])) ? 'OK' : 'Non');