leksione te www

Shiko temën e mëparshme Shiko temën pasuese Shko poshtë

leksione te www

Mesazh nga Admin prej Fri May 16 2008, 09:15

LEKSION 1



Ambjenti I punes

n P3 256 mb ram 40 g hdd

n Os: Windows xp pro sp1,2, windows 2k pro sp4

n Web server : IIS 4 ,5(windows component)

n php 4.3

n my sql

n Phpmyadmin

n IDE- Macromedia Dreamweaver

n SQL Server 2000 Pers. Edition

n Adobe Photoshop

n Macromedia Fireworks

n Macromedia Flash , Swish 3D

Niveli i aplikimit

Konceptimi dhe implementimi i aplikimeve ne rrjet

Ne kete leksion

n Koncepte baze te nivelit te aplikimit

n Protokollet , klientet , serverat , proceset , xhepat dhe ndefaqesimi me nivelin e transportit

n Protokolle te nivelit te aplikimit

n HTTP

n SMTP

n FTP

n DNS

Parimet e protokolleve te nivelit te aplikimit

n Ne nje aplikimi ne rrjet kemi gjithmone dy procese qe shkembejne mesazhe me njeri-tjetrin

n Shembull web,telnet, ftp, smtp etj

n Mesazhet transportohen nepermjet nderfaqes me nivelin e transportit

n Aplikimet e rrjetit kane gjithmone protokolle ne nivelin e aplikimit qe percaktojne formatin ,rendin dhe veprimet qe duhen ndermarre kur dergohen dhe merren keto mesazhe

Klient dhe server Sockets

n Proceset dergojne dhe marrin mesazhe nepermjet sockets te tyre

n Socket I nje procesi eshte “dera e nje procesi”

n Jashte dyerve ka nje infrastrukture transporti qe do te transportoje mesazhin neper internet deri tek dera e procesit tjeter

Adresimi I proceseve

n Identifikuesi I sockets perbehet nga dy pjese

n Adresa e kompjuterit ku ndodhet procesi

n Numri i portes qe identifikon ne menyre te vetme procesin brenda kompjuterit



n Nje socket

n 192.168.1.1:80

n Identifikon procesin e web serverit qe ndodhet ne makinen me adrese ip 192.168.1.1

HTTP :80

n Percaktohet ne RFC 1945 de RFC 2616

n Ka dy pjese : klient , server qe komunikojne me njeri-tjetrin duke shkenbyer mesazhe http

n Web server ruan objektet web sejcili I adresueshem nepermjet URL

n HTTP percakton se si web browserat kerkojne faqe web dhe se si serveri ia transmeton ato klientit

n HTTP eshte protokoll pa gjendje





Mesazhet e http

n Ka dy mesazhe :

n Request

n Response

Mesazhi request

n Shembull

n GET /train/skedar1.html HTTP/1.1

n Request line

n Host: www.ictstudio.net

n Connection: close

n User-agent: Mozilla /4.0

n Accept language:fr

n Header lines



analiza



n Request line ka 3 argumenta

n Method / URL / http version

n Method = GET/POST

n Header line

n Connection: close – lidhje jo persistente , mbyllet me dergmin e skedarit

n User-agent = lloji I browserit

n Accept-language tregon qe perdoruesi preferon permbajtje ne gjuhen frenge

n Eshte vetem nje nga headerat per negociimin e permbajtjes ne http

n Nese perdoruesi ka dhene vlera ne faqe kerkese keto vendosen ne pjesen e trupit qe eshte ne fund te emsazhit

n Kryesisht kurperdor metoden post

Mesazhi response

n HTTP/1.1 200 ok

n Connection:close

n Date: ……kur ui krijua pergjigja nga serv

n Server: Appache /1.3.0

n Last modified

n Content –Length

n Content-Type: text/html

n data-data-data

Status kodet

n 200- ok

n 301- moved permanenetly, shoqerohet me nje header location tek url e objektit. Browseri duhet te beje ridrejtimin automatikisht

n 400 – bad request

n 404- not found

n 505 – http version non supported

FTP - 21

n Ndryshe nga http , ftp perdor dy lidhje tcp per te transferuar nje skedar

n Lidhje kontrolli

n Dergon informacione kontrolli username , password , komanda

n Lidhje te dhanash

n Dergon skedarin



Lidhja e kontrollit qendron e hapur gjate gjithe sesionit

Per cdo sekdar krijohet dh mbyllet nje lidhje e re

SMTP

n Komanda HELO

n MAIL FROM :

n RCPT TO:

n DATA

n ….

n . r







DNS

n ROOT HINTS

n Forward DNS

n Shembull web browsing

n Reverse DNS

Shembull email filte

Strukture peme hierarkike

n Perkthimi nis nga fundi

Rekordet DNS

n (emri, vlera,tipi,ttl)

n TIPE:

n A- Adrese

n MX- mail exchange

n NS- domain server



n Komanda nslookup

Ushtrime



n Telnet web 80

n ftp server

n ls – list

n get

n put

n Smtp server

n Helo me , mail from , rcpt to , data .

n Nslookup server


Edituar për herë të fundit nga Admin në Fri May 16 2008, 10:35, edituar 1 herë gjithsej

Admin
Admin
Admin

Numri i postimeve : 97
Age : 29
Localisation : Tirane
Registration date : 13/03/2007

Shiko profilin e anëtarit http://mirazh.msnyou.com

Mbrapsht në krye Shko poshtë

Leksioni 2

Mesazh nga Admin prej Fri May 16 2008, 10:29

Pjesa e pare


PHP beggining


Php language

PHP is a very popular HTML-embedded server side scripting language

Scripts written directly in HTML code for a given page (escaping).

The PHP code is embedded between <?php (or <?) and ?>

It has been developed from Perl: therefore it resembles Perl, C, Java

It has been specially developed for HTML use

Works both via a properly configured webserver and direct from prompt (php).

Some important properties

  • Variables have dynamic types and need not be declared
  • (Associative) Arrays (i.e., maps, hashes)
  • Support for GET and POST by http and working easily with databases.
  • Classes and objects
  • HTML forms and Cookies






On scripting languages

Instances: JavaScript, Perl, PHP,....

Interpreted instead of compiled.

No strong typing.

Variables not (necessarily) declared

More often, instantiated on encounter.

Dangerous in case your typing qualities are not great.

Type of a variable not fixed: lots of (mysterious) implicit casts and

assignments may change the type of a variable.

Generally, scripting languages are loose and hence demand great discipline.

Most interpreters have flags for strict/paranoid execution. Use them.

Control structures often C/Java-like

Special control structures like foreach, but also interpolation.

Often special support for regular expressions, hashes and arrays.



On the side of the server

JavaScript runs on the client (the browser)

Included in HTML: everybody can see your code.

JavaScript can be turned off (outside your control).

PHP is executed by the server.

When you request a PHP file all you get is the result (usually html):

The server copies the html.

When it encounters PHP code it executes it and replaces the code by the

result.

In this way the whole PHP file is processed top to bottom.

Admin
Admin
Admin

Numri i postimeve : 97
Age : 29
Localisation : Tirane
Registration date : 13/03/2007

Shiko profilin e anëtarit http://mirazh.msnyou.com

Mbrapsht në krye Shko poshtë

Leksioni 2

Mesazh nga Admin prej Fri May 16 2008, 10:32


Pjesa e dyte






Types


Available are (as in most other languages)

  • booleans,
  • integers (usually 32 bits, usual operations),
  • floating point numbers (decimal, scientific),
  • strings,
  • (associative) arrays (very powerful compared to Java),
  • classes,
  • resources and
  • NULL for unset variables. Use isset($v) to check for definedness.


PHP includes a lot of type juggling.

Takes a lot of remembering, but it can be worse.

Booleans


booleans, true and false

What is equivalent to false?

false of course, and FALSE,....

the integer 0, the float 0.0,

the empty string ””, but also the string ”0”. Not the string ”0.0” though.

the special value NULL.

an array with zero elements

an object with zero members

The rest is true.

Hence True == "false" is true, because ”false” is converted to boolean

and then compared.

True === "false" is false: they must have the same type to to begin with.

empty($v) yields the opposite value of casting $v to bool.



Strings

Contain simple 8 bit characters.

$str = "A single quote is ’, right?";

$str = ’A double would be "!’;

Or escape them like in "Single (’) and double (\")".

Single quoted gives literal strings: no interpretation of what is inside the string.

Strings may run over multiple lines: whitespace is ignored by browser anyway.



Double quoted strings

The standard escape characters: \n, \t, \\, \$, \{, ...

Interpolation works easy for simple variables, but look out for arrays.

<?php

$name = "Blob";

echo ":$name:"; // yields :Blob:

echo "$namebo"; // yields empty string

echo "{$name}bo"; // yields Blobbo

$A[2][3] = $name;

echo "The {$A[2][3]}!"; // The Blob!

echo "The " . $A[2][3] . "!"; and again

echo "and not $A[2][3]." // and not Array[3]

?>







Useful string functions

Huge amount of useful functions (many familiar from other languages):

for concatenation: print "One" . " and " . "two";

strlen, printf, ltrim, trim, rtrim, str_pad,

strtolower, strtoupper, ucfirst, ucwords

strcmp, strncmp, strcasecmp,... (-1, 0, 1)

substr, strpos, strstr

$words = explode(" ","Jack in the box"),

implode("-",$words) prints as Jack-in-the-box.

strtr($posting, array("BTW" => "by the way", ....))

strtr("Thrakattak", "thrk", "THRK")

nl2br renders newlines in argument as <br>s.

strtotime for parsing ”15 November 2004”.

Functions for regular expressions (but not now)



Control structures

The same as in Java and C:

if (cond) {....} and an optional else {....}

for(init; cond; inc) { .... }

while (cond) { .... } and do {...} while (cond)

the terrible switch

continue and his buddy the break

conditions and expressions as in Java.

New to you may be:

if (cond) {....} elseif (cond) {....} elseif (cond) {....}

Array iteration in two different flavours

foreach ($students as $pupil) { echo("$pupil\n"); }

foreach ($library as $isbn => $title) {

echo "Book with ISBN $isbn has title $title";}



Arrays

Arrays map keys to values.

Values may be different for the same array: PHP arrays are heterogeneous.

Keys can only be strings or integers.

Integer indices may start anywhere (even negative), only the defined ones are

stored.

Otherwise we might talk of maps, associative arrays, hashes.

Arrays can be multidimensional (and anything in between).

$A = array("0 to String", 24, "something big");

$A[100] = array( 1 => "One", 20 => "Twenty", "a" => "One");

//A[3]-A[99]stillundefined.

echo ($A[100][’a’]); // Note the quotes.

$A[] = "My favourite room"; // Setting A[101]

unset ($A[2]); // Saving some memory.





Associative arrays

$AnArray = array (1 => "Dog", "Cat", "Scary" => "Bat");

$AnArray[0] = "Rat";

print_r($AnArray);

// Array ([1] => Dog [2] => Cat [Scary] => Bat [0] => Rat)

Arrays in PHP are in fact associative arrays mapping keys to values.

Remember that arrays are stored as keys mapping to values.

This can be important in case you assume anything about the order.

Best thing to do: do not think of them as arrays like in Java or C, even if the

keys are integers.

array_keys($AnArray) gives (1,2,"Scary",0)

array_value($AnArray) gives ("Dog","Cat","Bat","Rat")

foreach also considers them in this order.

Admin
Admin
Admin

Numri i postimeve : 97
Age : 29
Localisation : Tirane
Registration date : 13/03/2007

Shiko profilin e anëtarit http://mirazh.msnyou.com

Mbrapsht në krye Shko poshtë

Re: leksione te www

Mesazh nga Admin prej Fri May 16 2008, 10:33


Pjesa e trete






Useful array functions and constructs

$A = array (0, 2 => 2, 3);

$B = array (1 => "Dog", "Cat", "Scary" => "Bat", 0 => "Rat");

count gives the number of values. count($B) equals 4.

list($a, , $c) = $A; works only on integer indexed array: $c is now 2,

$a is 0 of course.

in_array (true or false) and array_search (returns key for the value,

false is not found.)

Use === to check result of array_search against false.

Some more useful ones:

max, min, array_flip, array_map, array_reverse



Sorting

$fruits = array("d"=>"lemon", "a"=>"orange", "b"=>"banana");

ksort($fruits); // a => orange, b => banana, d => lemon

asort($fruits); // b => banana, d => lemon, a =>orange

sort($fruits); // 0 => banana, 1 => lemon, 2 => orange

Huge amount of array (modifying) sort functions: sort(), asort(), arsort(),

ksort(), krsort(), rsort(), usort(), uasort(), uksort(), natsort, ....

sort is the basic function: reorders values, result has integer keys (0,1,...).

’r’ stands for reverse sorting

’u’ stands for sorting with user defined comparison function

Do not assume anything about where equivalent values end up!

’a’ stands for sorting on values, ’k’ stands for sorting on keys

The latter two keep mapping intact.

natsort sorts like a human would: ’img2.gif’ comes before ’img12.gif’.



Functions

function f ($arg_1, $arg_2, ..., $arg_n) {

echo "Example function.\n";

return $retval;

}

Avoiding duplication of code.

Exists both in classes (methods) and plain functions.

Names are case insensitive.

You may return multiple values by using arrays.

Both pass-by-value and pass-by-reference allowed.

For pass-by-reference add an ampersand:

function add_bang (&$string) { $string .= "!"; }



Global versus local scope

The scope of a variable is that part of the program where its value is visible.

Scoping in PHP is somewhat unexpected: every variable used in a function is

local, unless explicitly qualified by global.

Avoid global and pass what you need by reference instead.

There exist variables which are autoglobal, no need to state in every function

that they are global.

$a = 1; // global scope

function Test() {

// global $a;

echo $a; //reference to local scope variable

}

Test();



Include files

include "file" to include PHP sources.

if ($ie6 == true) include "ie.inc";

else include "other.inc";

Use this only for libraries of PHP functions and maybe some constants.

Avoid code that executes directly on include.

PHP code in includes should always be within <?php and ?>,

even if you put the include within PHP as well.

Give them the inc extension and let Apache forbid access to these files.

<Files ~ "\.inc$">

Order allow,deny

Deny from all

Satisfy All

</Files>

You can use it to store passwords and such.



Communication with PHP

A PHP script usually needs input from the outside world.

In the program we need access to these values.

Access to values via special variables in PHP. Use $_SERVER autoglobal array

to access server variables.

Contains many values like $_SERVER[’REQUEST_METHOD’].

Other important ones: $_GET, $_POST, $_ENV, $_COOKIE, $_FILES

Used to be HTTP_SERVER_VARS, HTTP_GET_VARS,....

In the GET method pairs of names and values are passed along.

For example: http://www.google.com/search.php?id=knor&n=10

if ($id==$_GET[’id’])

echo "User id $id was defined";

else

die "No user id";



Form example

<form action="gnarl.php" method="POST">

Name: <input type="text" name="username"><br>

Email: <input type="text" name="email"><br>

<input type="submit" name="submit" value="Submit me!">

</form>

<?php

// Preferred.

print $_POST[’username’]; // Available since PHP 4.1.0

print $_REQUEST[’username’]; // Cookies, GET and POST

import_request_variables(’p’, ’x_’); // p for POST

print $x_username;

print $HTTP_POST_VARS[’username’]; // Older PHP versions

// Available if the PHP directive register_globals = on.

// Using/relying on this method is not preferred.

print $username; ?>



Database connecting

PHP has built in database operations

Example for mySQL, other DBMSs are similar

First connect to the database.

@ sign to suppress standard error messages.

function showerror () {

die ("Error " . mysql_errno() . " : " . mysql_error());

}

if (!($cnx = @ mysql_connect("host", "login", "password")))

die("Could not connect.");

mysql_select_db("carbase", $cnx) or showerror();

...querying code...

mysql_close($cnx) or showerror()



Basic database querying

$u=$_REQUEST[‘username’]; //une

$p=$_REQUEST[‘password’]; // sot

$q=“select * from perdoruesit where username=‘”.$u.”’ and password=‘ ”.$p.” ’ ”;

select * from perdoruesit where username = ‘une’ and password=‘sot’





Mysql_query()

$res=Mysql_query(stringkomand)

Or die(“nuk ecen”);

if ($rec=mysql_fetch_array($res))

{

Echo “welcome ”.$u;

}

Else

{

Echo “username password nuk jane te sakte”;

Echo “<a href=‘login.php’>kliko per tu loguar perseri</a>”;

}



Afisho te gjithe studentet

$q=“ select * from studente where

qyteti=‘ ”.$_REQUEST(“qyteti”).” ’ order by emri,mbiemri ”;

$res=mysql_query($q)

or die(“nuk ecen”);

While $rec=mysql_fetch_array($res)

{

echo $rec[“emri”].” ”.$rec[“mbiemri”];

echo “<br>”;

}

Admin
Admin
Admin

Numri i postimeve : 97
Age : 29
Localisation : Tirane
Registration date : 13/03/2007

Shiko profilin e anëtarit http://mirazh.msnyou.com

Mbrapsht në krye Shko poshtë

Leksion 3

Mesazh nga Admin prej Fri May 16 2008, 11:02

Pjesa pare

My SQL






RDBMS

Relational Database Management System

Relacional – cdo e dhena e ruajtur eshte tabele – relacion

Tabela perbehet nga rreshta dhe kollona

Vlerat ruhen ne kollonat e tabeles

Ambjenti gjuha

phpma

sql= structured query language

DDL – Data Definition Language

Create database , create table , alter table

DML – Data Modification Language

Insert into table (clmn1,clmn2) values (vl1,vl2)

Vlera Boshe - NULL

NULL – asgje , vlere

Per te kontrolluar qe nje vlere e nje kollone te caktuar eshte null eshte operatori eshte null



KOMANDAT DDL

Komanda create table



Sintaksa



create table emertabele

(

column_1 column_type column attributes,

column_2 column_type column attributes,

primary key (column_name),

index index_name(column_name)

)

Ushtrim-Shembull :

beni export tabelen studentet dhe shikoni kodin qe gjeneron phpma

Gjeni ku jane emrat e kollonave , tipet e te dhenave , atributet

Disa atribute

null | not null

Lejon ose ndalon qe nje kollone te mos permbaje vlera

default

Percakton nje vlere qe merr nje kollona nese ne e leme bosh kur futim nje rresht ne tabele

auto_increment,

Vete_rrites – e vendos ne menyre automatike vleren e nje kollone te tipit int duke rritur me nje vleren me te madhe qe ka rreshti paraardhes

Psh nese I fundit ka qene 7 , vlera e re qe do te merret automatikisht do te jete 8(7+1)

Nese e fshijme nje rresht , id e tij nuk perdoret me , nuk I jepet nje rreshti tjeter.

Kjo mundeson identifikimin unik te rreshtave kur behet fjale per celesin primar

Tipet e kollonave

Tipe tekst

Char(n) (n<=255)

Fjale me gjatesi fikse me n shkrojna/numra

Shembull nr_amzes , Nr_targes te cileve I dihet numri I shkronjave

Varchar(n) (n<=255)

Fjale me gjatesi variabel 0 deri ne n shkronja

Tipe tekst vazhdon..

Tipet Tekst

Te gjithe tipet e meposhtme kane gjatesi variabel si ne rastin e varchar(n)

Ndryshojne nga njeri-tjetri nga gjatesia maksimale e tekstit qe mund te mbajne



TINYTEXT

Gjatesia maksimale eshte 255 karaktere



TEXT

Gjatesia maksimale eshte 65,535 karaktere



MEDIUMTEXT

Gjatesia maksimale 16,777,215 karaktere



LONGTEXT

Gjatesia maksimale 4,294,967,295 karaktere

Kjo kollone nuk perdoret shume pasi gjatesia maksimale e stringut qe lejon MySQL eshte vetem 16 milion byte

Admin
Admin
Admin

Numri i postimeve : 97
Age : 29
Localisation : Tirane
Registration date : 13/03/2007

Shiko profilin e anëtarit http://mirazh.msnyou.com

Mbrapsht në krye Shko poshtë

Re: leksione te www

Mesazh nga Admin prej Fri May 16 2008, 11:03

pjesa e dyte



ENUM

Perdorimi : enum (‘value1’, ‘value2’, ‘value3’ ...) [default ‘value’]

Mund te kufizohet numri i vlerave qe mund te marre nje kollone . Lejon deri 65535

Psh nese duam qe nje kollone e caktuar te marre vetem dy vlera te mundshme po dhe jo

psh

create table my_table (

id int auto_increment primary key,

Pyetje varchar(200),

Pergjigje enum (‘po’, ‘jo’) default ‘po’

);

Tipet numerike

MySQL ka shtate tipe kollonash per numrat

  • _ int/integer
  • _ tinyint
  • _ mediumint
  • _ bigint
  • _ float
  • _ double/double precision/real
  • _ decimal/numeric




Dallojne nga njeri-tjetri ne madhesi



Tipet per daten dhe kohen



_ date

_ time

_ datetime

_ year

_ timestamp

Tipet per kohen ne jane fleksibel, dhe pranojne stringje psh nese krijojme nje tabele

create table date_test(

id int unsigned auto_increment,

the_date date

);

Komandat e meposhtne interpertohen sakte nga mysql:

insert into date_test (a_date) values (‘00-06-01’);

insert into date_test (a_date) values (‘2000-06-01’);

insert into date_test (a_date) values (‘20000601’);

insert into test6 (a_date) values (000601);

Tipet e te dhenave per datat

DATE

Perdorimi : date

Te dhenat ruhen ne formatin YYYY-MM-DD. Lejon vlera nga

1000-01-01 deri ne 9999-12-31.

DATETIME

Perdorimi: datetime

Ruan te dhenat ne formatin:YYYY-MM-DD HH:MM:SS. Lejon vlera nga 1000-01-01 00:00:00 ne 9999-12-31 23:59:59.

TIMESTAMP

Perdorimi: timestamp(size)

Eshte nje kollone shume dobishme qe ruan ne menyr automatike kohen kur rreshti u modifiku

Tipe per datat

TIME

Perdorimi: time

SRuan kohen ne formatin HH:MM:SS dhe lejon vlera nga–838:59:59 ne

838:59:59. Arsyeja e vlerave te medha qendron tek fakti qe tipi I tedhenave time mund te perdoret per te ruajtur rezultatet e veprimeve matematike me kohen

YEAR

Perdorim : year[(2|4)]

Rekomandohet perdorimi me ka numra. Lejon vlera nga1901 en 2155.

Komandat DML

Komanda Insert

Sintaksa

insert into table_name (column_1, column2, column3,...) values

(value1, value2, value3 ...)



  • Nese nje kollone lejon vlera Null ath ju mund te mos e vendosni ate ne komanden insert




Stringjet duhet te vendoesn brenda thonjezave teke (‘).



shembull

insert into table_name (text_col, int_col) values (‘hello world’, 1)

Escape characters

Disa karaktere te vecanta mund te futen ne nje kollone duke I paraprire me backslash

Komanda update

Sintaksa

update table_name set col_1=value1, col_2=value_2

where col=value

Komanda select e thjeshte

Select [lista e kollonave te ndara me presja] from [ emri_tabeles]

where

kusht_llogjik

order by [liste e kollonave]



Komanda select me funksionet e grupit

Select [lista e kollonave te ndara me presja te grupuara], [funksion_grupi] from [ emri_tabeles]

where

[ kusht_llogjik]

Group by [lista e kollonave te ndara me presje te grupuara]

Having [kusht_llogjik]

Shembuj select i thjeshte

Select * from studentet

Select id,emri.mbiemri from studentet where datelindja is null

Shembuj select i perbere

Nga tabela studentet afishoni per sejcilin nga emrat sa here perseritet

Select emri,count(*) ‘ here’ from studentet

Group by emri



Nga tabela studentet afishoni te gjithe ata studente qe kane emer , mbiemer te njejte

Select emri,mbiemri,count(*) ‘here’ from studentet group by emri,mbiemri having count(*)>1

Ushtrime

Ne phpmyadmin

Provoni insert me datelindjen null

Futni disa studente me te njejtin emer me insert

Afishoni te gjithe studente qe vijne nga shkodra

Provoni te gjeni sa here perseritet cdo emer

Provoni te gjeni cilet jane studentet qe kane emer dhe mbiemer te njejte

String operators

Operator krahasim

Like

I kombinuar me wildcards

% - nje numer cfaredo char nga 0-n

? – nje karakter

Psh - studentet qe I fillon emri me a

Select emri , mbiemri from student

» Where emri like ‘a%’

Psh – studentet qe kane shkronjen e dyte a

select * from student where emri like ‘???-(04)-??????’

Admin
Admin
Admin

Numri i postimeve : 97
Age : 29
Localisation : Tirane
Registration date : 13/03/2007

Shiko profilin e anëtarit http://mirazh.msnyou.com

Mbrapsht në krye Shko poshtë

Re: leksione te www

Mesazh nga Admin prej Fri May 16 2008, 11:04

peypal



Instant Payment Notification
Instant Payment Notification (IPN) allows you to automate certain aspects of your business by posting transaction details to your server whenever you receive a PayPal payment or whenever a status change occurs on a transaction. When used with a credit card or Express Checkout transactions, IPN is not useful to get the status of a payment, but only to get asynchronous notification such as an eCheck clearing or a chargeback.

How IPN Works
When a customer pays you, PayPal posts a notification to your server at a URL you specify. Included in this notification are all of your customer's payment details (eg. customer name, amount) as well as a piece of encrypted code. The variables included in the notification are listed in the IPN Variable Reference.
When you receive the notification, you must post the entire message back to PayPal at a secure URL. This prevents spoofing by ensuring the original IPN came from PayPal. The URL is:
https://www.paypal.com/cgi-bin/webscr
If you are testing in the Sandbox, the URL is:
https://www.sandbox.paypal.com/cgi-bin/webscr
You must post all form variables exactly as you received them, and you must also append a variable named cmd with the value _notify-validate. PayPal verifies the transaction by checking the encrypted string.
PayPal then sends confirmation back to your server with a single word, "VERIFIED" or "INVALID", in the body of the response. Your IPN script should then post back a 200 OK response to prevent additional attempts by PayPal to post your transaction data. If PayPal does not receive the 200 OK response from your server, PayPal will resend the notification for up to four days.
If you receive an INVALID notification, it should be treated as suspicious and be investigated. If you receive a VERIFIED response, perform the following checks before fulfilling the order:

  • Confirm that the payment_status is Completed, since IPNs are also sent for other results such as Pending or Failed
  • Check that the txn_id is unique, to prevent a fraudster from reusing an old, completed transaction
  • Validate that the receiver_email is an email address registered in your PayPal account, to prevent the payment from being sent to a fraudster's account
  • Check other transaction details, such as the item number and price, to confirm that the price has not been changed. We also recommend using the custom or invoice variable to pass your own transaction ID that can you check.

Once you have completed the above checks, you can update your database with the IPN data and process the purchase.
This diagram shows the basic flow of an IPN transaction.
Instant Payment Notification







Activating IPN
There are two ways to activate Instant Payment Notification.
Option 1



1. Log in to your Premier or Business PayPal account.

2. Click Profile.

3. Click Instant Payment Notification Preferences.

4. Enter the URL at which you would like to receive IPN posts.
Option 2


Specify the URL in the notify_url variable on appropriate transaction types. If you specify an IPN URL in this manner, it will override the URL defined in your Profile settings.

Variable Reference
For a complete list of the possible variables that can be included in the IPN post that PayPal sends to your server, visit the IPN/PDT Variable Reference page.

Script Generator
PayPalTech.com offers a script generator to create sample IPN code for you to work from.

Additional Resource
Order Management Integration Guide (PDF, 2.7MB)
Instant Payment Notification forum in the PayPal Developer Community

Admin
Admin
Admin

Numri i postimeve : 97
Age : 29
Localisation : Tirane
Registration date : 13/03/2007

Shiko profilin e anëtarit http://mirazh.msnyou.com

Mbrapsht në krye Shko poshtë

Leksion 5

Mesazh nga Admin prej Fri May 16 2008, 11:09

Pjesa e pare

PHP


Gjuha PHP

PHP mjfat popullore si gjuhe skriptimi ne server, e perfshire ne HTML

Kodi PHP vendoset midis <?php dhe ?>

Eshte ndertuar bazuar ne Perl: prandaj eshte e ngjashme me Perl, C, Java

Funksionon si me webserver edhe me prompt - CLI

Veti kryesore

Variablat kane tipe dinamike dhe nuk ka nevoje te deklarohen

Array shume dimensionale

Support per GET dhe POST te http dhe punon lehstesisht me database.

Suporton klasat dhe objektet

Suporton sesionet dhe cookiet





Php ekzekutohet ne server !

JavaScript ekzekutohet ne klient (browser)

Vendoset ne HTML: mund ta shikoni ne browser kodin javascript.

JavaScript can be turned off (outside your control).

PHP ekzekutohet ne server.

Kur beni nje perkese per nje skedar PHP merrni si rezultat nje html:

Serveri thjesht kopjon kodin html qe gjen ne faqe

Kur gjen kod php e ekzekuton ate dhe zevendeson kodin me rezultatin e eekzekutimit

Keshtu procesohet skedari php nga fillimi ne fund



Shembull

  • <html>
  • <head>
  • <title>shembull 2</title>
  • <?php
  • $name=“Endri”;
  • ?>
  • </head>
  • <body>
  • <b>
  • <?php
  • echo “Pershendetje ”.$name;
  • ?>
  • </b>
  • </body>
  • </html>




Rezultati

Design view

Pershendejtje Endri



Code view

<html>

<head>

<title>shembull 2</title>

</head>

<body>

<b>

Pershendetje Endri

</b>

</body>

</html>



Tipet

Boolean,

integer (zakonisht 32 bits)

floating point numbers (decimal, sshkencore),

stringjet,

(associative) arrays (shume me fleksibel se ne Java),

Klasat,

Resources dhe

NULL varialbla pa vlere. Nepermjet funksionit isset($v) kontrollohet nese nje variabel ekziston



Boolean

Booleans, true dhe false

Cfare eshte ekuivalente me false?

false,....

integer 0, the float 0.0,

Stringu bosh ””,

Vlera NULL.

Nje array me zero elemente

Te tjerat jane true



Stringjet

Permbajne karaktere 8 bit.

$str = "A single quote is ’, right?";

$str = ’A double would be "!’;

Escape neperjmet (\")".

Stringjet mund te zgjaten ne disa rreshta.



Funksione me stringjet

o Per konktateminim: print "One" . " and " . "two";

o strlen, ltrim, trim, rtrim

o strtolower, strtoupper

o int strcmp ( string str1, string str2) (-1, 0, 1)

o string substr ( string string, int start [, int length])

o nl2br newlines -> <br>

Admin
Admin
Admin

Numri i postimeve : 97
Age : 29
Localisation : Tirane
Registration date : 13/03/2007

Shiko profilin e anëtarit http://mirazh.msnyou.com

Mbrapsht në krye Shko poshtë

Re: leksione te www

Mesazh nga Admin prej Fri May 16 2008, 11:09

Pjesa e dyte




Strukturat e kontrollit

  • Te ngjashme me Java dhe C:
  • if (cond) {....} opional else {....}
  • for(init; cond; inc) { .... }
  • while (cond) { .... }
  • do {...} while (cond)
  • the terrible switch




Arrays

Arrays lidhin emrat me vlera.

Vlerat mund te jene te ndryshme brenda te njejtit array

array jane heterogjen.

Celesat mund te jene vetem strings ose integers.

Mund ti konsiderojme si harta , hashes , peme.

Arrays mund te jene multidimensional



Funksionet

function f ($arg_1, $arg_2, ..., $arg_n) {

echo “Funksion shembull.\n";

return $retval;

}

Emrat jane case insensitive.

Mund te ktheni disa vlera duke kthyer array

Kalimi I argumentave si vlere ose si reference

Per kalimin e references perdoret nje &

function add_bang (&$string) { $string .= "!"; }



Ambjenti i variablave

o Ambjenti I nje variabli eshte pjesa e programit ku ai eshte vizibel

o Cdo variabel I perdorur ne nje funksion eshte local nese nuk specifikohet ne menyre eksplicite si global.

o Mos perdorni global por kaloni argumentat si reference kur eshte e nevojshme

o $a = 1; /* global scope */

o function Test() {

o // global $a;

o echo $a; /* reference to local scope variable */

o }

o Test();



Inkludimi i skedareve

  • include "file“;




  • Mos perdorni kod qe ekzekutohet ne include
  • Kodi PHP en include duhet te jete gjithmone midisi<?php dhe ? >,
  • Vendosini prapashtesen inc




Komunikimi me kodin PHP

Nje script PHP ka nevoje per input.

Ne program kemi nevoje per te kapur keto vlera

Vlerat kapen nepermjet variablave te vecante ne

array autoglobal $_SERVER ruan te gjithe variablat e serverit

PSh $_SERVER[’REQUEST_METHOD’].

Te tjere shembuj: $_GET, $_POST, $_COOKIE, $_FILES

Ne metoden GET kalohen cifte emer vlere

Psh

http://www.google.com/search.php?id=knor&n=10

if ($id==$_GET[’id’])

echo "User id”. $id. “was defined";

else

die "No user id";



Shembull i nje forme

  • <form method="POST">
  • Name: <input type="text" name="username"><br>
  • Email: <input type="text" name="email"><br>
  • <input type="submit" name="submit" value="Submit me!">
  • </form>
  • <?php
  • //
  • If (isset($_REQUEST[‘submit’])
  • {
  • echo $_POST[’username’]; // Available since PHP 4.1.0
  • echo $_REQUEST[’username’]; // Cookies, GET and POST
  • echo $_REQUEST[email’]; // Cookies, GET and POST
  • }
  • ?>




Lidhja me bazen e te dhenave

  • PHP ka “built in database operations”
  • Shembull per mySQL, DBMS te tjere jane te ngjashem
  • Lidhja me DB
  • mysql_connect("host", "login", "password")
  • or die("Could not connect.");
  • mysql_select_db("carbase") or
  • die (mysql_error());
  • Querit ne DB




Veprime baze me DB

$u=$_REQUEST[‘username’]; //une

$p=$_REQUEST[‘password’]; // sot

$q=“select * from perdoruesit where username=‘”.$u.”’ and password=‘ ”.$p.” ’ ”;

Vlera e stringut – sql dinamike

select * from perdoruesit where username = ‘une’ and password=‘sot’



Mysql_query()

  • $res=Mysql_query($q)
  • or die(“nuk ecen”);
  • if ($rec=mysql_fetch_array($res))
  • {
  • Echo “welcome ”.$u;
  • }
  • Else
  • {
  • Echo “username password nuk jane te sakte”;
  • Echo “<a href=‘login.php’>kliko per tu loguar perseri</a>”;
  • }






Select ne db
Afisho te gjithe studentet



    • $q=“ select * from studente where
    • qyteti=‘ ”.$_REQUEST(“qyteti”).” ’ order by emri,mbiemri ”;
    • $res=mysql_query($q)
    • or die(“nuk ecen”);
    • while $rec=mysql_fetch_array($res)
    • {
    • echo $rec[“emri”].” ”.$rec[“mbiemri”];
    • echo “<br>”;
    • }


Admin
Admin
Admin

Numri i postimeve : 97
Age : 29
Localisation : Tirane
Registration date : 13/03/2007

Shiko profilin e anëtarit http://mirazh.msnyou.com

Mbrapsht në krye Shko poshtë

Re: leksione te www

Mesazh nga Sponsored content Today at 14:21


Sponsored content


Mbrapsht në krye Shko poshtë

Shiko temën e mëparshme Shiko temën pasuese Mbrapsht në krye

- Similar topics

 
Drejtat e ktij Forumit:
Ju nuk mund ti përgjigjeni temave të këtij forumi