Visualizzazione dei risultati da 1 a 10 su 10
  1. #1

    Codice da controllare...

    Salve, vorrei che mi aiutaste a capire una cosa:
    Ho cercato di sistemare una tag già esistente è mi è riuscito bene... Ora, la cosa che non riesco a fare è che quando si scrive l'url "www." nell'input url, venga automaticamente impostato "http://www.", perché altrimenti da lo sgradevole errore di link interno... Vi metto di seguito la parte del codice interessata...

    Codice PHP:
    if($stats == 1){
        
    $date date("d M y");
        
    $time date("G:i");
    if(!isset(
    $url) || $url == "" ){    
        
    $write "[size="1"]<div align=\"right\">$date$time</div>[b]$name[/b] $cjmsg
    [/size]\r\n"
    ;
        }
        else {
        
    $write "[size="1"]<div align=\"right\">$date$time</div>[b]<a href=\"$url\" target=\"_blank\">$name</a>[/b] $cjmsg
    [/size]\r\n"
    ;
       }
    else{
        
    $write "[size="1"]<div align=\"right\">$date$time</div>[b]$name[/b] $cjmsg
    [/size]\r\n"
    ;
    }
    $tagomfile file($datfile); 
    Come vedete, ho capito come fare per impostare che se il campo è vuoto, non ci sia il tag <a href, ma non capisco come fare per far si che si imposti automaticamente http quando manca... Risulterebbe utile anche da persone che potrebbero mettere nell'imput javascript... Così mi proteggerei doppiamente... Spero di essere stato chiare, grazie mille in anticipo

  2. #2
    Utente di HTML.it L'avatar di dottwatson
    Registrato dal
    Feb 2007
    Messaggi
    3,012
    sei stato chiaressimo

    Codice PHP:
    if($stats == 1){
        
    $date date("d M y");
        
    $time date("G:i");
    if(!isset(
    $url) || $url == "" ){    
        
    $write "[size="1"]<div align=\"right\">$date$time</div>[b]$name[/b] $cjmsg
    [/size]\r\n"
    ;
        }
     else {
        if (
    substr($url,0,7)=="ftp://"$url=substr($url,7);    
        if (
    substr($url,0,7)!="http://"$url="http://$url";
        
    $write "[size="1"]<div align=\"right\">$date$time</div>[b]<a href=\"$url\" target=\"_blank\">$name</a>[/b] $cjmsg
    [/size]\r\n"
    ;
       }

    else{
        
    $write "[size="1"]<div align=\"right\">$date$time</div>[b]$name[/b] $cjmsg
    [/size]\r\n"
    ;
    }
    $tagomfile file($datfile); 
    Non sempre essere l'ultimo è un male... almeno non devi guardarti le spalle

    il mio profilo su PHPClasses e il mio blog laboweb

  3. #3

    ;__;

    Purtroppo mi da errore... Eccoti il codice php completo:
    Codice PHP:
    <?php

    // Defining Program Variables ------------------------------------------------------------------------//

    include("config.php");

    $name $_POST['name'];
    $cjmsg $_POST['cjmsg'];
    $url $_POST['url'];
    $ip $_SERVER['REMOTE_ADDR'];
    $agent $_SERVER['HTTP_USER_AGENT'];
    $added_time time();

    // Checking for banned IPs ----------------------------------------------------------------------------//

    $banned_array file($ipbanfile);
    foreach (
    $banned_array as $key => $bip) {
        if(
    $ip == trim($bip)){
            
    header("location: {$display}?msg=<font color=maroon>Banned:</font>
    You have been banned from using the Tag Board <img src=e/razz.gif>

    "
    );
            exit;
        }
    }

    // Checking for flooders ------------------------------------------------------------------------------//

    if(flooder($ip)){
       
    header("location: {$display}?msg=<font color=maroon>Flood Protection:</font>
    You must wait 
    $flood_time seconds before posting again

    &flood=on"
    );
       exit;
    }
    else{
        
    $floodfp fopen($floodfile"a");
        
    fwrite($floodfp"$added_time|$ip|\n");
        
    fclose($floodfp);
    }

    // Checking for blank fields -------------------------------------------------------------------------//

    $sub_error false;
    $sub_emsg "<font color=maroon>Missing Items:</font>
    "
    ;

    if(!isset(
    $name) || $name == ""){            // if some idiot just clicks "tag"
        
    $sub_emsg .= "[*]Name";
        
    $sub_error true;
    }
    if(!isset(
    $cjmsg) || $cjmsg == ""){
        
    $sub_emsg .= "[*]Tag";
        
    $sub_error true;
    }
    if(
    $sub_error){
        
    header("location: {$display}?msg=$sub_emsg

    "
    );
        exit;
    }

    // Replacing and converting ------------------------------------------------------------------------//

    $cjmsg str_replace("&lt;","<"$cjmsg);
    $cjmsg str_replace("&gt;",">"$cjmsg);
    $cjmsg strip_tags($cjmsg);                    // strips HTML tags from tag
    $name strip_tags($name);                        // strips all HTML tags from name
    $ename $name;                                        // sets email name
    $cjmsg ubbCode($cjmsg);

    if(
    $smilies == 1){
        
    $cjmsg convertSmilies($cjmsg);
    }

    // Bad Word Filter function

    foreach($badword_array as $insult=>$ok){
            
    $cjmsg eregi_replace("$insult""$ok""$cjmsg");
            }

    foreach(
    $badword_array as $insult=>$ok){
            
    $name eregi_replace("$insult""$ok""$name");
            }

    ############################################################
    ############################################################

    $name .= ":";
    $person $name;
    $name $person;

    if(
    $stats == 1){
        
    $date date("d M y");
        
    $time date("G:i");
    if(!isset(
    $url) || $url == "" ){    
        
    $write "[size="1"]<div align=\"right\">$date$time</div>[b]$name[/b] $cjmsg
    [/size]\r\n"
    ;
        }
    else {
        if (
    substr($url,0,7)=="ftp://"$url=substr($url,7);    
        if (
    substr($url,0,7)!="http://"$url="http://$url";
        
    $write "[size="1"]<div align=\"right\">$date$time</div>[b]<a href=\"$url\" target=\"_blank\">$name</a>[/b] $cjmsg
    [/size]\r\n"
    ;
       }
    $tagomfile file($datfile);

    if (
    $cjmsg != "") {
        if (
    strlen($cjmsg) < 2000) {            // after converting smilies...
            
    $fd fopen ($datfile"w");

            
    $write stripslashes($write);        
            
            
    fwrite ($fd$write);
                for (
    $count 0$count $NUM_COMMENTS-1$count++) {
                    
    fwrite ($fd$tagomfile[$count]);
                }

                if(
    $printall == 1){
                        
    $alltagomfile file($datfileall);
                        
    $amount count($alltagomfile);

                        
    $fdall fopen ($datfileall"w");

                        
    fwrite ($fdall$write);
                            for (
    $counter 0$counter <= $amount+1$counter++) {
                                
    fwrite ($fdall$alltagomfile[$counter]);
                            }
                        
    fclose($fdall);
                    }
        }
    fclose($fd);

    // Write the counter....

    require("tagcount.txt");

    $countfilename "tagcount.txt";
    $increment $tagcount 1;
    $incrementoutput "<? $" "tagcount = " $increment "; ?>";
    $countwrite fopen($countfilename"w");
    fwrite ($countwrite$incrementoutput);
    fclose($countwrite);

    }

    // email the admin?

    if($send_notify == "yes"){
        
    $cjmsg strip_tags($cjmsg);                    // strips potential smilies from tag
        
    $recipient "$yourname <$email>";
        
    $subject "You have been Tagged!";
        
    $message "$yourwebsite has been tagged!\nOn: $date - $time\n\nName: $ename\n\nMessage: $cjmsg";
        
    $headers "From: $ename <$email>\r\nReply-To: $email\r\n";
        
    mail ($recipient$subject$message$headers);
    }

    // else dont do anything to the data file

    header("location: {$display}?msg=Thanks for posting $ename

    "
    );
    exit;

    function 
    flooder($ip){
        global 
    $flood_time$floodfile;

        
    $old_db file($floodfile);
        
    $new_db fopen($floodfilew);
        
    $result FALSE;
        foreach(
    $old_db as $old_db_line){
            
    $old_db_arr explode("|"$old_db_line);
            if((
    $old_db_arr[0] + $flood_time) > time() ){
                
    fwrite($new_db$old_db_line);
                if(
    $old_db_arr[1] == $ip){ 
                    
    $result TRUE
                }
            }
        }
        
    fclose($new_db);
        return 
    $result;
    }

    function 
    ubbCode($text){
        
    // Array of tags with opening and closing
        
    $tagArray['b'] = array('open'=>'[b]','close'=>'[/b]');
        
    $tagArray['i'] = array('open'=>'[i]','close'=>'[/i]');
        
    $tagArray['u'] = array('open'=>'<u>','close'=>'</u>');
        
    $tagArray['url'] = array('open'=>'[url="','close'=>'"]\\1[/url]');
        
    $tagArray['email'] = array('open'=>'[email="','close'=>'"]\\1[/email]');
        
    $tagArray['url=(.*)'] = array('open'=>'[url="','close'=>'"]\\2[/url]');
        
    $tagArray['email=(.*)'] = array('open'=>'[email="','close'=>'"]\\2[/email]');
        
    $tagArray['color=(.*)'] = array('open'=>'<font color="','close'=>'">\\2</font>');
        
    $tagArray['quote'] = array('open'=>'<table border="0" width="100%" cellspacing="0" cellpadding="0"><tr><td style="border: 1px dotted #000000">[b]Quote:[/b]
    '
    ,'close'=>'</td></tr></table>');

        foreach(
    $tagArray as $tagName=>$replace){
             
    $tagEnd=preg_replace('/\W/Ui','',$tagName);
             
    $text preg_replace("|\[$tagName\](.*)\[/$tagEnd\]|Ui","$replace[open]\\1$replace[close]",$text);
        }
        return 
    $text;
    }

    function 
    convertSmilies($cjmsg){
        
    $cjmsg str_replace(":D","<img src=\"e/grin.gif\">"$cjmsg);
        
    $cjmsg str_replace(":)","<img src=\"e/smile.gif\">"$cjmsg);
        
    $cjmsg str_replace(":lol","<img src=\"e/lol.gif\">"$cjmsg);
        
    $cjmsg str_replace(":p","<img src=\"e/razz.gif\">"$cjmsg);
        
    $cjmsg str_replace(":evil","<img src=\"e/evil.gif\">"$cjmsg);
        
    $cjmsg str_replace(":(","<img src=\"e/sad.gif\">"$cjmsg);
        
    $cjmsg str_replace(":|","<img src=\"e/shocked.gif\">"$cjmsg);
        
    $cjmsg str_replace(";)","<img src=\"e/wink.gif\">"$cjmsg);
        
    $cjmsg str_replace(":x","<img src=\"e/mad.gif\">"$cjmsg);
        
    $cjmsg str_replace(":cry","<img src=\"e/cry.gif\">"$cjmsg);
        
    $cjmsg str_replace(":blink","<img src=\"e/rolleyes.gif\">"$cjmsg);
        
    $cjmsg str_replace(":o","<img src=\"e/suprised.gif\">"$cjmsg);
        
    $cjmsg str_replace(":?","<img src=\"e/question.gif\">"$cjmsg);
        
    $cjmsg str_replace(":s","<img src=\"e/confused.gif\">"$cjmsg);
        
    $cjmsg str_replace("B)","<img src=\"e/cool.gif\">"$cjmsg);
        
    $cjmsg str_replace(":red","<img src=\"e/redface.gif\">"$cjmsg);
        
    $cjmsg str_replace("u_u","<img src=\"e/u_u.gif\">"$cjmsg);
        
    $cjmsg str_replace("-w-","<img src=\"e/mah.gif\">"$cjmsg);
        
    $cjmsg str_replace("^w^","<img src=\"e/happy.gif\">"$cjmsg);
        
    $cjmsg str_replace("^.^","<img src=\"e/weppa.gif\">"$cjmsg);

        
    $cjmsg str_replace("\n",""$cjmsg);    
        
    $cjmsg str_replace("\r",""$cjmsg);
        return 
    $cjmsg;
    }

    ?>
    Cioè, dove hai detto tu non da errore, ma mi da errore dove finisce il codice php... Come posso fare? Scusa il disturbo e grazie... P.S.: Se vuoi vedere la tag-board che sto usando, poi metto il link (se non è spam)...

  4. #4
    Utente di HTML.it L'avatar di dottwatson
    Registrato dal
    Feb 2007
    Messaggi
    3,012
    mi dici il messaggio di errore completo perfavore?
    Non sempre essere l'ultimo è un male... almeno non devi guardarti le spalle

    il mio profilo su PHPClasses e il mio blog laboweb

  5. #5
    Parse error: parse error in c:\hosting\pkmnisland.com\wwwroot\public\tag-board\tag.php on line 217

  6. #6
    Utente di HTML.it L'avatar di dottwatson
    Registrato dal
    Feb 2007
    Messaggi
    3,012
    ok corretto

    Codice PHP:
    <?php

    // Defining Program Variables ------------------------------------------------------------------------//

    include("config.php");

    $name $_POST['name'];
    $cjmsg $_POST['cjmsg'];
    $url $_POST['url'];
    $ip $_SERVER['REMOTE_ADDR'];
    $agent $_SERVER['HTTP_USER_AGENT'];
    $added_time time();

    // Checking for banned IPs ----------------------------------------------------------------------------//

    $banned_array file($ipbanfile);
    foreach (
    $banned_array as $key => $bip) {
        if(
    $ip == trim($bip)){
            
    header("location: {$display}?msg=<font color=maroon>Banned:</font>
    You have been banned from using the Tag Board <img src=e/razz.gif>

    "
    );
            exit;
        }
    }

    // Checking for flooders ------------------------------------------------------------------------------//

    if(flooder($ip)){
       
    header("location: {$display}?msg=<font color=maroon>Flood Protection:</font>
    You must wait 
    $flood_time seconds before posting again

    &flood=on"
    );
       exit;
    }
    else{
        
    $floodfp fopen($floodfile"a");
        
    fwrite($floodfp"$added_time|$ip|\n");
        
    fclose($floodfp);
    }

    // Checking for blank fields -------------------------------------------------------------------------//

    $sub_error false;
    $sub_emsg "<font color=maroon>Missing Items:</font>
    "
    ;

    if(!isset(
    $name) || $name == "")
      {            
    // if some idiot just clicks "tag"
      
    $sub_emsg .= "[*]Name";
      
    $sub_error true;
      }
      if(!isset(
    $cjmsg) || $cjmsg == "")
        {
        
    $sub_emsg .= "[*]Tag";
        
    $sub_error true;
        }
    if(
    $sub_error){
        
    header("location: {$display}?msg=$sub_emsg

    "
    );
        exit;
    }

    // Replacing and converting ------------------------------------------------------------------------//

    $cjmsg str_replace("&lt;","<"$cjmsg);
    $cjmsg str_replace("&gt;",">"$cjmsg);
    $cjmsg strip_tags($cjmsg);                    // strips HTML tags from tag
    $name strip_tags($name);                        // strips all HTML tags from name
    $ename $name;                                        // sets email name
    $cjmsg ubbCode($cjmsg);

    if(
    $smilies == 1){
        
    $cjmsg convertSmilies($cjmsg);
    }

    // Bad Word Filter function

    foreach($badword_array as $insult=>$ok){
            
    $cjmsg eregi_replace("$insult""$ok""$cjmsg");
            }

    foreach(
    $badword_array as $insult=>$ok){
            
    $name eregi_replace("$insult""$ok""$name");
            }

    ############################################################
    ############################################################

    $name .= ":";
    $person $name;
    $name $person;

    if(
    $stats == 1)
      {
      
    $date date("d M y");
      
    $time date("G:i");
      if(!isset(
    $url) || $url == "" )
        {    
        
    $write "[size="1"]<div align=\"right\">$date$time</div>[b]$name[/b] $cjmsg
    [/size]\r\n"
    ;
        }
      else 
        {
        if (
    substr($url,0,7)=="ftp://"$url=substr($url,7);    
        if (
    substr($url,0,7)!="http://"$url="http://$url";
        
    $write "[size="1"]<div align=\"right\">$date$time</div>[b]<a href=\"$url\" target=\"_blank\">$name</a>[/b] $cjmsg
    [/size]\r\n"
    ;
        }
      }
    else
      {
      
    $write "[size="1"]<div align=\"right\">$date$time</div>[b]$name[/b] $cjmsg
    [/size]\r\n"
    ;
      } 
    $tagomfile file($datfile);

    if (
    $cjmsg != "") {
        if (
    strlen($cjmsg) < 2000) {            // after converting smilies...
            
    $fd fopen ($datfile"w");

            
    $write stripslashes($write);        
            
            
    fwrite ($fd$write);
                for (
    $count 0$count $NUM_COMMENTS-1$count++) {
                    
    fwrite ($fd$tagomfile[$count]);
                }

                if(
    $printall == 1){
                        
    $alltagomfile file($datfileall);
                        
    $amount count($alltagomfile);

                        
    $fdall fopen ($datfileall"w");

                        
    fwrite ($fdall$write);
                            for (
    $counter 0$counter <= $amount+1$counter++) {
                                
    fwrite ($fdall$alltagomfile[$counter]);
                            }
                        
    fclose($fdall);
                    }
        }
    fclose($fd);

    // Write the counter....

    require("tagcount.txt");

    $countfilename "tagcount.txt";
    $increment $tagcount 1;
    $incrementoutput "<? $" "tagcount = " $increment "; ?>";
    $countwrite fopen($countfilename"w");
    fwrite ($countwrite$incrementoutput);
    fclose($countwrite);

    }

    // email the admin?

    if($send_notify == "yes"){
        
    $cjmsg strip_tags($cjmsg);                    // strips potential smilies from tag
        
    $recipient "$yourname <$email>";
        
    $subject "You have been Tagged!";
        
    $message "$yourwebsite has been tagged!\nOn: $date - $time\n\nName: $ename\n\nMessage: $cjmsg";
        
    $headers "From: $ename <$email>\r\nReply-To: $email\r\n";
        
    mail ($recipient$subject$message$headers);
    }

    // else dont do anything to the data file

    header("location: {$display}?msg=Thanks for posting $ename

    "
    );
    exit;

    function 
    flooder($ip){
        global 
    $flood_time$floodfile;

        
    $old_db file($floodfile);
        
    $new_db fopen($floodfilew);
        
    $result FALSE;
        foreach(
    $old_db as $old_db_line){
            
    $old_db_arr explode("|"$old_db_line);
            if((
    $old_db_arr[0] + $flood_time) > time() ){
                
    fwrite($new_db$old_db_line);
                if(
    $old_db_arr[1] == $ip){
                    
    $result TRUE;
                }
            }
        }
        
    fclose($new_db);
        return 
    $result;
    }

    function 
    ubbCode($text){
        
    // Array of tags with opening and closing
        
    $tagArray['b'] = array('open'=>'[b]','close'=>'[/b]');
        
    $tagArray['i'] = array('open'=>'[i]','close'=>'[/i]');
        
    $tagArray['u'] = array('open'=>'<u>','close'=>'</u>');
        
    $tagArray['url'] = array('open'=>'[url="','close'=>'"]\1[/url]');
        
    $tagArray['email'] = array('open'=>'[email="','close'=>'"]\1[/email]');
        
    $tagArray['url=(.*)'] = array('open'=>'[url="','close'=>'"]\2[/url]');
        
    $tagArray['email=(.*)'] = array('open'=>'[email="','close'=>'"]\2[/email]');
        
    $tagArray['color=(.*)'] = array('open'=>'<font color="','close'=>'">\2</font>');
        
    $tagArray['quote'] = array('open'=>'<table border="0" width="100%" cellspacing="0" cellpadding="0"><tr><td style="border: 1px dotted #000000">[b]Quote:[/b]
    '
    ,'close'=>'</td></tr></table>');

        foreach(
    $tagArray as $tagName=>$replace){
             
    $tagEnd=preg_replace('/W/Ui','',$tagName);
             
    $text preg_replace("|[$tagName](.*)[/$tagEnd]|Ui","$replace[open]\1$replace[close]",$text);
        }
        return 
    $text;
    }

    function 
    convertSmilies($cjmsg){
        
    $cjmsg str_replace("[img]images/smilies/biggrin.gif[/img]","<img src=\"e/grin.gif\">"$cjmsg);
        
    $cjmsg str_replace("[img]images/smilies/smile.gif[/img]","<img src=\"e/smile.gif\">"$cjmsg);
        
    $cjmsg str_replace(":lol","<img src=\"e/lol.gif\">"$cjmsg);
        
    $cjmsg str_replace(":p","<img src=\"e/razz.gif\">"$cjmsg);
        
    $cjmsg str_replace(":evil","<img src=\"e/evil.gif\">"$cjmsg);
        
    $cjmsg str_replace("[img]images/smilies/frown.gif[/img]","<img src=\"e/sad.gif\">"$cjmsg);
        
    $cjmsg str_replace(":|","<img src=\"e/shocked.gif\">"$cjmsg);
        
    $cjmsg str_replace(";)","<img src=\"e/wink.gif\">"$cjmsg);
        
    $cjmsg str_replace(":x","<img src=\"e/mad.gif\">"$cjmsg);
        
    $cjmsg str_replace(":cry","<img src=\"e/cry.gif\">"$cjmsg);
        
    $cjmsg str_replace(":blink","<img src=\"e/rolleyes.gif\">"$cjmsg);
        
    $cjmsg str_replace(":o","<img src=\"e/suprised.gif\">"$cjmsg);
        
    $cjmsg str_replace(":?","<img src=\"e/question.gif\">"$cjmsg);
        
    $cjmsg str_replace(":s","<img src=\"e/confused.gif\">"$cjmsg);
        
    $cjmsg str_replace("B)","<img src=\"e/cool.gif\">"$cjmsg);
        
    $cjmsg str_replace(":red","<img src=\"e/redface.gif\">"$cjmsg);
        
    $cjmsg str_replace("u_u","<img src=\"e/u_u.gif\">"$cjmsg);
        
    $cjmsg str_replace("-w-","<img src=\"e/mah.gif\">"$cjmsg);
        
    $cjmsg str_replace("^w^","<img src=\"e/happy.gif\">"$cjmsg);
        
    $cjmsg str_replace("^.^","<img src=\"e/weppa.gif\">"$cjmsg);

        
    $cjmsg str_replace("\n",""$cjmsg);    
        
    $cjmsg str_replace("\r",""$cjmsg);
        return 
    $cjmsg;
    }

    ?>
    Non sempre essere l'ultimo è un male... almeno non devi guardarti le spalle

    il mio profilo su PHPClasses e il mio blog laboweb

  7. #7
    Ti adoro ù_ù! Sei un grande! Senza di te non sapevo come fare! Ti sarò devoto a vita xDDD! Comunque, se ti servirà qualcosa come grafica o consigli html, rivolgiti pure a me, farò qualsiasi cosa (nei miei limiti) per ripagarti ^_^! Grazie ancora!

  8. #8
    Utente di HTML.it L'avatar di dottwatson
    Registrato dal
    Feb 2007
    Messaggi
    3,012
    figurati.. è stato un piacere

    ti ho mandato un pvt
    Non sempre essere l'ultimo è un male... almeno non devi guardarti le spalle

    il mio profilo su PHPClasses e il mio blog laboweb

  9. #9
    Codice PHP:
    if (substr($url,0,7)=="ftp://"$url=substr($url,7); 
    VVoVe:

  10. #10
    volendo ti puoi anche divertire a validare l'indirizzo con javascript e le regular expressions

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.