Showing posts with label PHP Coding. Show all posts
Showing posts with label PHP Coding. Show all posts

Friday, 19 October 2012

PHP ( Tutorials V )


Type Of Juggle In PHP

Type Juggling means dealing with a variable type. In PHP a variables type is determined by the context in which it is used. If an integer value is assigned to a variable, it becomes an integer.

E.g. $var3= $var1 + $var2

Here, if $var1 is an integer. $var2 and $var3 will also be treated as integers.  

Difference Between Include And Require

Require () and include () are the same with respect to handling failures. However, require () results in a fatal error and does not allow the processing of the page. i.e. include will allow the script to continue. 

How To Submit Form Without A Submit Button

A form data can be posted or submitted without the button in the following ways:

1. On OnClick event of a label in the form, a JavaScript function can be called to submit the form.

E.g. document.form_name.submit()

2. Using a Hyperlink: On clicking the link, JavaScript function can be called.

E.g <a.href=” javascript:document.MyForm.submit();">

Urlencode And Urldecode

Urlencode can be used to encode a string that can be used in a url. It encodes the same way posted data from web page is encoded. It returns the encoded string.

Syntax: urlencode (string $str )

Urldecode can be used to decode a string. Decodes any %## encoding in the given string (Inserted by urlencode)

Syntax: urldecode (string $str )

Differences Between Require And Include, Include_Once

Include () will include the file specified.

Include_once () will include the file only once even if the code of the file has been included before.

Require () and include () are the same with respect to handling failures. However, require () results in a fatal error and does not allow the processing of the page.







Functions For IMAP In PHP


IMAP is used for communicate with mail servers. It has a number of functions. Few of them are listed below:

Imap_alerts – Returns all the imap errors occurred

Imap_body – Reads the message body

Imap_check – Reads the current mail box

Imap_clearflag_full – Clears all flags

Imap_close – close and IMAP stream

Imap_delete – Delete message from current mailbox

Imap_delete_mailbox – Deletes a mailbox

Imap_fetchbody – Fetches body of message

Imap_fetchheader – Fetches header of message

Imap_headers – Returns headers for ALL messages

Imap_mail : send a mail

Imap_sort- Sorts imap messages

Different types of errors in PHP


Different types of Errors are:

E_ERROR: A fatal error that causes script termination

E_WARNING: Run-time warning that does not cause script termination


E_PARSE: Compile time parse error.


E_NOTICE: Run time notice caused due to error in code


E_CORE_ERROR: Fatal errors that occur during PHP's initial startup (installation)


E_CORE_WARNING: Warnings that occur during PHP's initial startup 


E_COMPILE_ERROR: Fatal compile-time errors indication problem with script.


E_USER_ERROR: User-generated error message. 


E_USER_WARNING: User-generated warning message. 

E_USER_NOTICE: User-generated notice message. 
 
E_STRICT: Run-time notices.
 
E_RECOVERABLE_ERROR: Catchable fatal error indicating a dangerous error
 
E_ALL: Catches all errors and warnings 

Difference Between $message and $$message In PHP


Explain the difference between $message and $$message.

$message is used to store variable data. $$message can be used to store variable of a variable. Data stored in $message is fixed while data stored in $$message can be changed dynamically.
E.g. $var1 = ‘Variable 1’
$$var1= ‘variable2’
This can be interpreted as $ Variable 1=‘variable2’;
For me to print value of both variables, I will write
$var1 $($var1)

Persistent Cookie

Cookies are used to remember the users. Content of a Persistent cookie remains unchanged even when the browser is closed. ‘Remember me’ generally used for login is the best example for Persistent Cookie.

Monday, 17 September 2012

How To Use CSS and HTML in the Same Statement


To use both CSS and HTML in the same statement, but it is considered best to push as much of the formatting as possible into CSS, and the <font> tag is one that people say to avoid. In your example, you can do all the styling with CSS: 

<h1 style="text-align:center; font-family:arial,sans-serif; font-size:large;">Text Here</h1> 

I hope I got that mostly right. There are various ways to specify font size. I chose one that might not be the exact equivalent of size=5. 

Alternatively, you can put a separate style declaration in your page, or even in a separate .css file, which makes it much easier to make site-wide changes. This would style all h1 tags: 

h1 

text-align:center; 
font-family:arial,sans-serif; 
font-size:large; 
} 

Friday, 14 September 2012

Simply Create Drop Down Menu

     Dropdown Menu

A Dropdown list is a combination of items in a list. In the dropdown list menu only the title is visible but not the contents. The contents are shown only when the user activates it by a small arrow. The user may select an item from the menu by dragging the mouse from the menu title or by clicking the title and then clicking the item. The dropdown list box is read-only.


We can say a drop down list is a box containing a list of multiple items. A drop-down list is a list in which the selected item is always visible, and the others are visible on demand by clicking a drop-down button.

The main advantages of a drop down list is to save space because the number of views is not limited by space.

There are two types of dropdown lists, which are as follows:
  • Static dropdown list
  • Dynamic dropdown list
Source Code:  Download

Simply image upload in PHP with MYSQL


Hi I have read many forums and websites that tell you how to upload an image to a server and I have managed to get this working, I can upload a file to a my server but storing the file name does work on the following example I found and I also need to create a form that allows more data to be entered to the database. I am stuck with this as a have done much php before. I have come to the end of trying different websites tutorals with no much success could anyone please help me! I need it done for a project im doing. 

If you want to use the image upload in your websites then you click the download option and enjoy is this coding.........

Source Code:   Download

Classes Use in PHP


Class definition:

include('snapshot.class.php');
$myimage = new ImageSnapshot;
$myimage->ImageField = $_FILES['userfile'];
$myimage->Width = 100;
$myimage->Height = 100;
$myimage->Resize = true;
$myimage->ResizeScale = 50;
$myimage->Position = 'center';
$myimage->Compression = 80;

If you want to save the altered image as a file:

if ($myimage->SaveImageAs('temp.jpg')) {
echo '<img src="temp.jpg" border="0" alt="test" />';
} else {
echo $myimage->Err;
}

OR if you want to get the contents of the saved image as a variable:

if ($myimage->ProcessImage() !== false) {
$img = $myimage->GetImageContents();
} else {
echo $myimage->Err;
}


Imagefield

This variable holds the exact array of the $_FILES field that you specify. If the file is not a valid image (jpg, gif, png) the class will return an error when SaveImageAs or ProcessImage is called.

Wednesday, 12 September 2012

PHP ( Tutorial III )


What is Session Handling in PHP

There are many ways that session handling can be used to provide a dynamic and non-static experience for the end user. session can be used for providing a more personal experience for the end user by keeping track of them as they roam through a site providing concept that is more trailored to their likes and dislikes.Session can also be used to make a valid usernamr and password can gain access to  apart of any sites, or in the case of any online store.

MYSQL is a perfect companion to session handling to help with the process of storing and retrieving the data that gives extra life to the session handling capabilites........

PHP ( Tutorial II )


PHP Secure

Having connection information stored in a plain readable fashion can be disconcerting to many new web developers; however, with the right security steps, this can be less of a concern. The following are some steps that should be addressed to make sure that the informaiton is Kept secure:
 

 Operatin System Rights- Almost every operating system provides a mean to limit access to files
by end users in one fashion or another.

Remote Connections- In the example up to the point, the connection have been made to localhost;
however, there are setups in which a connection is made to an external server that requires sending information throught an interconnect of some sort.

PHP ( Tutorials I )


PHP Authenticate

Simple coding of securing page in PHP.

If you want to login in the permission base,mean same page open in the many password then to use a following Code.This code Save in PHP and run to the localhost server.The below code has three username and password combinations. A function has also been added that will be used to check if a user has been logged in and will be used to authenticate many user on same page to login......

This code Save the name of  password.php and run the localhost server. 

<?php

$v=sha1('pass1');

Echo $v;

?>


Shown below code save a text file and you want to create a many password in the same method but  you  to change the value of pass1 every time and the output is different -2....

output is:9e5ca6b0ffb417997ffb844c76f9c24bbc20fe88


Then to use a following code and save the password_login.php......

<?php

$authorized_user=FALSE;

if (isset($_SERVER['PHP_AUTH_USER']) && isset ($_SERVER['PHP_AUTH_PW']))

{

$autharray=file("http://URL.txt");

foreach($autharray as $row) {

list ($user,$pswd)=explode(":",$row);

$pswd=trim($pswd);

if (($_SERVER['PHP_AUTH_USER']==$user) &&

(sha1($_SERVER['PHP_AUTH_PW'])==$pswd))  {

$authorized_user=TRUE;

break;

}   

}

}

if (!$authorized_user)  {

header('www-authenticate:basic realm="Photo album" ');

header('Http/1.0  401 unauthorized');

print "invalid user name and password ! ";

exit;

}

else

echo "Welcome <br>";

?>