Archive for the 'php' Category



05
Dec

AJAX php: vérifier si un user est déjà enregistré…

AJAX php: vérifier si un user est déjà enregistré sans avoir à re-charger la page

PHP:
  1. function RemoteRequestObject()
  2.  {
  3.   var A = false;  
  4.   try  {   A = new ActiveXObject(“Msxml2.XMLHTTP”);  }
  5.   catch(e)
  6.   {  try  {    A = new ActiveXObject(“Microsoft.XMLHTTP”);  }
  7.    catch(err)   {    A = false;   }
  8.   }
  9.  
  10.   if(!A && typeof(XMLHttpRequest) != ‘undefined’)
  11.    A = new XMLHttpRequest();
  12.   return A;
  13.  }
  14.  
  15.  function validateUser(oForm) {
  16.    var x = RemoteRequestObject();
  17.   oForm.onsubmit = function()
  18.   {
  19.  
  20.   if (oForm.annee.value==“annee”) {
  21.   alert(“Entrez votre année de naissance”);
  22.   oForm.annee.focus();
  23.   return false;
  24.   
  25.  }
  26.  if (oForm.email.value.indexOf(“@”) == -1 || oForm.email.value.indexOf(“.”) == -1 ||  oForm.email.value == “”)
  27.  {
  28.   alert(“Veuillez entrer un email valide”);
  29.   oForm.email.focus();
  30.   return false;
  31.  }
  32.  
  33.  if (oForm.pseudo.value==“”) {
  34.   alert(“Choissez un pseudo”);
  35.   oForm.pseudo.focus();
  36.   return false;
  37.  }
  38.  if (oForm.motdepasse.value==“”) {
  39.   alert(“Choissez un mot de passe”);
  40.   oForm.motdepasse.focus();
  41.   return false;
  42.  }
  43.  
  44.  if (oForm.cgu.checked==false) {
  45.   alert(“Vous devez accepter les conditions générales d’utilisation”);
  46.   oForm.cgu.focus();
  47.   return false;
  48.  
  49.  }
  50.  
  51.    var usr=oForm.elements[‘pseudo’].value;
  52.    var url = “ajax.php?pseudo=”+usr;
  53.    x.open(“GET”,url,true);
  54.    x.onreadystatechange=function()
  55.    {
  56.     if(x.readyState == 4 && x.status == 200)
  57.     {
  58.      var r = x.responseText;
  59.      if(r.indexOf(“OK”) == 0)
  60.      {
  61.       oForm.submit();
  62.      }
  63.      else
  64.      {
  65.       alert(“Le pseudo que vous avez choisi est déjà utilisé!\nVeuillez le changer!”);
  66.     form3.pseudo.focus();
  67.      }
  68.     }
  69.    };
  70.    x.send(null);
  71.    return false;
  72.   }
  73.  
  74.  }

 

Le fichier ajax.php contient

PHP:
  1. <!–p require_once(‘Connections/con1.php’);<br–>mysql_select_db($database_con1, $con1);
  2.     $sql = “SELECT * FROM chat WHERE pseudo = ‘$pseudo’”;
  3.     $result = mysql_query($sql) or die(mysql_error());
  4.  
  5.     if(mysql_num_rows($result)>0)
  6.     {
  7.         echo “KO”;
  8.     }
  9.     else
  10.     {
  11.         echo “OK”;
  12.     }
  13. ?>

04
Dec

phpBB et url rewrite

Comment réaliser un url-rewrite sur phpBB ? Continue reading ‘phpBB et url rewrite’

18
Oct

Comment verifier qu’un lien pointe bien vers votre site ? BACKLINK check

Comment verifier qu’un lien pointe bien vers votre site ?

Une simple fonction PHP vous permer de le faire !
function check_back_link($remote_url, $your_link) {
    $match_pattern = preg_quote(rtrim($your_link, “/”), “/”);
    $found = false;
    if ($handle = @fopen($remote_url, “r”)) {
        while (!feof($handle)) {
            $part = fread($handle, 1024);
            if (preg_match(“/\”‘]”.$match_pattern.
“(\/?)[\”‘](.*)>(.*)<\/a>/”, $part)) {
                $found = true;
                break;
            }
        }
        fclose($handle);
    }
    return $found;
}
// example:
//if (check_back_link(”http://www.capuccino.com”, “http://www.another.com”)) echo “link exists”;
?>

..,                 = ;                ;                            ;        ;

09
Oct

supprimer erreurs javascript

JAVASCRIPT:
  1. <script language=“javascript”>
  2. var track_errors=1;
  3. function noError()
  4. {
  5.   if (track_errors==1)
  6.      {
  7.         return true;
  8.      }
  9. }
  10. window.onerror = noError;
  11. </script>

03
Oct

Pages HTML avec footer et header fixes

HTML:
  1. <!– Put IE into quirks mode –>
  2. <meta http-equiv=“Content-Type” content=“text/html; charset=UTF-8″ />
  3. <title></title>
  4. <? $hh=100;
  5. $hf=50; ?>
  6.  
  7. <style type=“text/css”>
  8.  
  9. body {
  10.  height:100%;
  11.  max-height:100%;
  12.  overflow:hidden;
  13.  padding:0;
  14.  margin:0;
  15.  border:0;
  16.  }
  17.  
  18. #content {
  19.  display:block;
  20.  overflow:auto;
  21.  position:absolute;
  22.  z-index:3;
  23.  top:<?=$hh;?>px;
  24.  bottom:<?=$hf;?>px;
  25.  width:100%;
  26.  border-left:1px solid #000;
  27.  border-right:1px solid #000;
  28.  }
  29.  
  30. * html #content {
  31.  top:0;
  32.  bottom:0;
  33.  height:100%;
  34.  width:100%;
  35.  border-top:<?=$hh;?>x solid #fff;
  36.  border-bottom:<?=$hf;?>px solid #fff;
  37.  }
  38.  
  39. #head {
  40.  position:absolute;
  41.  top:0;
  42.  width:100%;
  43.  min-width:640px;
  44.  height:<?=$hh;?>px;
  45.  font-size:1em;
  46.  z-index:5;
  47.  border:1px solid #000;
  48.  }
  49.  
  50.  
  51.  
  52. #foot {
  53.  position:absolute;
  54.  bottom:0;
  55.  width:100%;
  56.  min-width:640px;
  57.  height:<?=$hf;?>px;
  58.  z-index:5;
  59.  border:1px solid #000;
  60.  }
  61.  
  62.  
  63.  
  64. </style>
  65. </head>
  66.  
  67. <div id=“head”>hello world</div>
  68. <div id=“foot”>THIS IS FOOTER</div>
  69. <div id=“content”>
  70. A layout with a fixed width, a fixed header and a fixed footer that stays on the bottom. The content area fits between the header and footer and scrolls if necessary. Plus the bonus of a CSS navigation menu that works in all browsers.

05
Sep

PHP MYSQL expiration date abonnement

$query_mois = “SELECT forumUsers.email FROM forumUsers where
forumUsers.date_expiration_inscription=TO_DAYS(now()) -30″;

// expiration dans 30 jours

 

10
Aug

PHP et PAYPAL

générer un PDT
https://paypaltech.com/PDTGen/generate_pdt.php

 

générer un SG2
http://paypaltech.com/SG2/PHPDbSQL.php

18
Jun

flex amfPHP tutorial

SQL:
  1. CREATE TABLE ‘users’ (
  2.   ‘userid’ int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  3.   ‘username’ varchar(255) collate latin1_general_ci NOT NULL,
  4.   ‘emailaddress’ varchar(255) collate latin1_general_ci NOT NULL,
  5.   PRIMARY KEY  (‘userid’)
  6. ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=3 ;

puis créer un fichier php: sample.php

PHP:
  1. <!–p<br–>// Create new service for PHP Remoting as Class
  2. class sample
  3. {
  4.     function sample ()
  5.     {
  6.         // Define the methodTable for this class in the constructor
  7.         $this->methodTable = array(
  8.             “getUsers” => array(
  9.                 “description” => “Return a list of users”,
  10.                 “access” => “remote”
  11.             )
  12.         );
  13.     }
  14.  
  15.     function getUsers () {
  16.         $mysql = mysql_connect(localhost, “username”, “password”);
  17.        
  18.         mysql_select_db( “sample” );
  19.        
  20.         //return a list of all the users
  21.         $Query = “SELECT * from users”;
  22.         $Result = mysql_query( $Query );
  23.         while ($row = mysql_fetch_object($Result)) {
  24.                $ArrayOfUsers[] = $row;
  25.         }
  26.         return( $ArrayOfUsers );
  27.     }
  28. }
  29. ?>

 

et enfin… le code FLEX… simple non ?

XML:
  1. http://www.adobe.com/2006/mxml" xmlns="*" creationComplete="initApplication()">
  2.    
  3.        
  4.            
  5.            
  6.            
  7.        
  8.    
  9.     <script>undefined</script><script>undefined</script>

 

lien: http://www.adobe.com/devnet/flex/articles/flex2_amfphp_03.html

 

18
Jun

flex et amfPHP

2 options pour le renvoi des données dans Flex

  • Utilsation des tableaux Arrays
PHP:
  1. while ($row = mysql_fetch_object($Result))
  2. {
  3. $myArray[] = $row;
  4. }
  5. return $myArray;

 

  • ou renvoi direct du recordset mysql_query
PHP:
  1. return mysql_query($query);

 

Le premier cas permet de faire des traitements/test php avant le renvoi des données (attention si vous souhaitez mettre les données dans un datagrid et utiliser les fonctions de tri: si vos données sont des nombres faire un

settype($maval, “integer”)

avant le renvoi, sinon amfphp reverra sous le format texte et flex triera les données comme du texte)

 

18
Jun

amfPHP tutorials

Point de départ:

http://www.amfphp.org/videotuts.html

Installation et utilisation de amfPHP pour FLASH