admin@qureshiuniversity.com

Admissions | Contact Us | Examinations | Grants | Instructors | Lecture | Membership | Recommendations | Research Grants | Librarians | Booksellers | Forms | Continents/States/Districts | Contracts | Students login | Universities | Volunteer

What is PHP?
Answer - PHP (Hyper text Pre Processor) is a scripting language commonly used for web applications.............

Example
What Is a Session in PHP?
PHP Session Variables

When you are working with an application, you open it, do some changes and then you close it. This is much like a Session. The computer knows who you are. It knows when you start the application and when you end. But on the internet there is one problem: the web server does not know who you are and what you do because the HTTP address doesn't maintain state.

A PHP session solves this problem by allowing you to store user information on the server for later use (i.e. username, (shopping, activities), etc). However, session information is temporary and will be deleted after the user has left the website. If you need a permanent storage you may want to store the data in a database.

Sessions work by creating a unique id (UID) for each visitor and store variables based on this UID. The UID is either stored in a cookie or is propagated in the URL.

-------------------------------------------------------------------------------- Starting a PHP Session

Before you can store user information in your PHP session, you must first start up the session.

Note: The session_start() function must appear BEFORE the tag:







The code above will register the user's session with the server, allow you to start saving user information, and assign a UID for that user's session.

What are sessions?

PHP tracks which file it's using for which user based on the session ID. This is a string of letters and numbers that are (ideally) unique to the visitor, making it easy for PHP to match the viewer and the file.

Why do I want to use them?

How do I use them?

And now we get to the big question (and hopefully some code, eh?) - how to use these uber-handy, simple, slick little bits of functionality PHP has to offer. Well, thankfully, the answer's pretty simple - and it all starts with one function:

Pretty simple, right? There has to be more to it, right? Wrong. Really, that's all it takes to start using sessions in your code. Keep in mind, though, that to be able to use your session on other pages, a call to session_start must be the first thing on every page. So, you have your session started - what are you going to do with it? Well, as I mentioned before, sessions are really just a handy place to store things. For example, if I started up my session and wanted to put a value of "enygma" into the "username" place, I'd do something like:





You'll notice two new things here - first is the format: $_SESSION[]. $_SESSION is one of the special variables that PHP handles internally, known as the superglobals. These variables (such as $_SESSION, $_GET, and $_POST) all have their places in PHP's functionality. They're also all arrays to make storing lots of data in them (or pulling from them) a much simpler process. So, using a simplified syntax to enter the value into the array, we push the value "enygma" into the $_SESSION array under the key of 'username'.

Get it? Got it? Good! On with the show!

Okay, so can you give me an example? Now we get down to the fun part, applying this knowledge to a simple, small example - just passing data from one page to another. There's two files we'll create: file1.php and file2.php. File1.php will be the one setting the data and file2.php will just display what we set before. Now here's some code...

File1.php:

go to file2
'; ?>

File2.php:



It's a very simple example, but it gets the main idea across - bridging the gap between pages with the help of sessions. There's lots more to learn about sessions and some other handy ways to use them, but that'll have to be for another time. For now, play with the examples provided here, and enjoy the new-found freedom of being able to connect pages together without all of that messy URL line handling.

Introduction To PHP Sessions

Contents

1. What is a session?
2. How do I use a Session?
3. How do sessions work?
4. How do I change the value of a session variable?
5. Can I destroy a session variable?
6. What should I do to destroy a whole session?
7. Can I store an array in a session?
8. Can I store an object in a session?
9. Can I store an file pointer in a session?
10. Can I store a function in a session?
11. Can I store an image in a session?
12. How are sessions stored?
13. Storing sessions with SQLite
14. When do sessions expire?
15. How can I send headers then start a session?
16. How can I check if a session is started?
17. How can I check if a session uses a cookie or query string
18. Session Configuration with php.ini
19. Session security

PHP Session

Explain the difference between $message and $$message?
Answer - $message is used to store variable data. $$message can be used to store variable of a variable.............

How to set cookies in PHP?
Answer - Cookies are often used to track user information.............

What is the difference between include and require?
Answer - Require () and include () are the same with respect to handling failures.............

What is urlencode and urldecode?
Answer - Urlencode can be used to encode a string that can be used in a url.............

What are the different types of errors in PHP?
Answer - Different types of errors are............

Explain how to submit form without a submit button.
Answer - A form data can be posted or submitted without the button in the following ways:............

What are the functions for IMAP?
Answer - IMAP is used for communicate with mail servers. It has a number of functions.............

How can we increase the execution time of a php script?
Answer - Default time allowed for the PHP scripts to execute is 30s defined in the php.ini file.............

What is Type juggle in php?
Answer - Type Juggling means dealing with a variable type. In PHP a variables type............

What is the difference between mysql_fetch_object and mysql_fetch_array?
Answer - Mysql_fetch_object returns the result from the database as objects while............

What is the difference between the functions unlink and unset?
Answer - Unlink is a function for file system handling which deletes a file.............

What is Joomla in PHP?
Answer - Joomla is an open source content management system.............
What is zend engine?

Answer - Zend Engine is used internally by PHP as a complier and runtime engine.............
What is the difference between Split and Explode?
Answer - Both the functions are used to Split a string. However, Split is used to split............

What is the difference between echo and print statement?
Answer - Echo can accept multiple expressions while print cannot.............

What is CAPTCHA?
Answer - CAPTCHA is a test to determine if the user using the system............

What is difference between developing website using Java and PHP?
Answer - In order to make interactive pages, java uses JSP (Java Server pages).............

How do you create sub domains using PHP?
Answer - Wild card domains can be used. Sub domains can be created by first creating............

How to upload files using PHP?
Answer - Files can be uploaded in PHP by using the tag type=”file”.............

What is the difference between Notify URL and Return URL?
Answer - Notify URL and Return URL is used in Paypal Payment Gateway integration.............

Describe functions STRSTR() and STRISTR.
Answer - Both the functions are used to find the first occurrence of a string.............

What are the various methods to pass data from one web page to another web page?
Answer - Different methods to pass data from one web page to another:............

Explain how to execute a PHP script using command line.
How can we increase the execution time of a PHP script?
Explain the purpose of output buffering in PHP.
Describe session in PHP.
How can we know the number of days between two given dates using PHP?
Explain how to execute a PHP script using command line.
PHP script using command line can be executed using SAPI (Server Application programming Interface). Using SAPI Command Line Interface the PHP code can be passed to execute directly

Example:
Php –r ‘print_r(get_defined_constanrs());’

From a shell, php –v will display whether the SAPI is CLI or CGI

How can we increase the execution time of a PHP script?
By default the PHP script takes 30secs to execute. This time is set in the php.ini file. This time can be increased by modifying the max_execution_time in seconds. The time must be changed keeping the environment of the server. This is because modifying the execution time will affect all the sites hosted by the server.

Explain the purpose of output buffering in PHP.
Output buffering in PHP buffers a scripts output. This buffer can be edited before returning it to the client. Without output buffering, PHP sends data to the web server as soon as it is ready. Output buffering "send" cookies at any point in the script. Cookies do not have to be necessarily sent near the start of page. Output buffers are stackable and hence sending to output is by choice.

Describe session in PHP.
When a user logs in an application, his details are usually stored in a session variable. This information is available to all pages in one application. Sessions in PHP work using a unique id for each visitor.

How can we know the number of days between two given dates using PHP?
The start date and end date can be first found as shown below:
$date1= strotime($start_date);
$date2= strotime($end_date);
$date_diff = (($date1)- ($date2)) / (60*60*24)

http://www.careerride.com/PHP-sessions.aspx