miercuri, 9 noiembrie 2011

Webpage correct title, description and image when sharing on facebook

I was sharing a link on facebook and I noticed the title of the page is not correct. Went back to my page, changed my title and still no succes. It seemed facebok was cache-ing this information.
SOLUTION: To remove the cache from Facebook go to this page http://developers.facebook.com/tools/debug and enter your URL.
It would also be helpful to provide special meta tags for facebook on your web page:

<meta property="og:title" content="title" />
<meta property="og:description" content="description" />
<meta property="og:image" content="thumbnail_image" />
 
More details here: http://developers.facebook.com/docs/share/ 

If you have any questions feel free to comment here.

vineri, 28 ianuarie 2011

PHP error: Strict Standards PEAR::isError()

Last day I tried to make a script for sending mail via PHP using SMTP, the script looked something like this:


require_once "Mail.php"; 

$from = "FROMmail@mail.com"; 
$to = "TOmail@mail.com"; 
$subject = "Subject";
$body = "Body text";     

$host = "mail.mail.com"; 
$username = "FROMmail@mail.com";
$password = "mail.com_pass";
$headers = array ('From' => $from,
  'To' => $to,
   'Subject' => $subject);
$mail = new Mail();
$smtp = & $mail->factory('smtp',
array ('host' => $host,
     'auth' => true,
     'username' => $username,
     'password' => $password));
if(PEAR::isError($smtp->send($to,$headers,$body)))
{
$error = $mail->getMessage();
}
else 
{
$msg = 'Mail send';
} 
The code above generated a bunch of Strict Standards errors, like the one here:


Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /usr/share/php/Net/SMTP.php


As the error states the Pear::isError is called statically but the function was not declared as so. This is probably because of a compatibility issue between PHP 4 and PHP 5, and inside PEAR scripts there are a lot of calls to this PEAR::isError() and all the calls are statical.
To solve this problem you go to /usr/share/php/ open the PEAR.php file and at line 250 you will find the function isError just add static in front of the function declaration. Try again and you should see the Strict Standards errors no more.
You may find similar errors in the Mail.php file, don't be shy, go and check the files and make the appropriate changes, that's the big benefit of Open Source.  

luni, 7 decembrie 2009

3006 A parser error has occurred.

I made some changes today on my website and suddenly I got this warning: Event Code 3006 A parser error has ocured in the event viwer log. My website stoped to function giving a runtime error.
It took me a while to work this around but this is what solved my problems:

1. Stop your server
2. Go to Windows\Microsoft.NET\Framework\v2.0.50...\Temporary ASP.NET Files\
3. Delete everything inside this folder
4. Restart your server and than it should work

I hope this will work for you to.

marți, 29 ianuarie 2008

Destructorul in clasele C++

De fiecare data cand creati o instanta a obiectului ce l-ati creat se executa constructorul automat, ei bine inainte de distrugerea obiectului se apeleaza automat functia destructor. Functiile destructor au aceeasi denumire ca si clasa. Diferenta fata de destructori este ca au in fata caracterul tilda ~ care trebuie sa preceada numele fiecarei functii destructor.
Functiile destructor nu accepta parametri si nici nu returneaza valori. Deci intodeauna prototipul functiei destructor va arata asa: ~NumeClasa();
Functiile destructor sunt necesare in special in momentul in care alocam dinamic memorie. Atunci cand toate datele sunt alocate static ex: int[10], char etc. C++ se va ocupa automat de o mare parte din procesul de distrugere, stergere a datelor. Daca insa datele membre sunt alocate dinamic este bine sa va asigurati ca acele date au fost sterse.
Ex:

class Carte
{
public:
char* titlu;
Carte(char* titlu = "Titlu");
~Carte();

};

Carte::Carte(char* titlu)
{
this->titlu = new [strlen(titlu)+1];
strcpy(this->titlu,titlu);
}
Carte::~Carte()
{
delete[] titlu;
}

Constructorii de clase in C++

Constructorul unei clase este o functie speciala care se excuta automat ori de cate ori programu creeaza o noua instanta de clasa. Functia constructor trebuie sa aiba acelasi nume cu clasa din care face parte si sa fie publica in cadrul clasei, adica accesibila tuturor. Functiile constructor nu returneaza valori.

Ex:


class Carte
{
public:
Carte(); //declararea constructorului

};



Functia constructor se executa in momentul in care se ajunge cu codul executabilului la declararea unei variabile de tipul clasei. Daca se intalnesc mai multe instante una dupa alta constructorul se executa in ordine de la stanga la dreapta de sus in jos, daca variabila este globala functia constructor se executa inainte de functia main.
Functiile constructor pot primi si parametri. Mai jos este un exemplu de clasa cu o mai multe functii constructor supraincarcate.


class Carte
{
int ID;
public:
char* titlu;
int nrPag;
Carte();
Carte(char* titlu);
Carte(Carte& c);

};
Carte::Carte()
{
ID = 0;
nrPag = 0;
titlu = new char[strlen("Titlu")+1];
strcpy(titlu,"Titlu");
}
Carte::Carte(char* titlu)
{
ID = 0;
nrPag = 0;
Carte::titlu = new char[strlen(titlu)+1];
strcpy(Carte::titlu,titlu);

}
Carte::Carte(Carte& c)
{
titlu = new char[strlen(c.titlu)+1];
strcpy(titlu,c.titlu);
nrPag = c.nrPag;
ID = c.ID;
}


Constructorul de mai sus ce primeste ca parametru prin referinta insasi clasa se numeste constructor de copiere. Acesta se apeleaza atunci cand se instantiaza o variabila cu ajutorul operatorului egal sau cand se copiaza pe stiva la apelul unei functii clasa noastra. ex cand initializam clasa c:
Carte d;
Carte c = d; //se porneste constructorul de copiere
o_functie(c); //cand se apeleaza aceasta functie se apeleaza si constructorul de copiere pentru variabila temporara ce va fi folosita in cadrul functiei.

c=d; //nu este pornit constructorul de copiere


Exercitiu:Creati clasa student ce are atributele: nume, vartsa si notaBac. Creati un constructor fara parametri, unul ce are 3 parametri si un constructor de copiere. In main trebuie sa fie initializati doi studenti unul prin constructor implicit altul prin constructorul cu parametri.Compilati si executati programul.