Friday, July 5, 2013

Why does the session value get deleted after the user deletes browser cookies?

How can we keep session value when user cookies are deleted?
 <?php
    session_start();
  echo $_SESSION['userdata']['name']='bikash';
?>
If user deletes the cookies, my session value has deleted. Please advise.

Answers:

As other posters have mentioned the cookies contains the session id which is required to access the session. However unless you perform a session_destroy() the actual session data can be still found on the directory which session files are stored.

If you have some other means of assigning a previous session to a user, for example if you have a database that maps ip addresses to session ids (bad idea!), then you could restore the previous session id usingsession_id().

Wednesday, July 3, 2013

how to download large pdf file using php header function ?SOLVE ISSUE

<?php
if($filepath!=''){
header('Pragma: public');  // required
header('Expires: 0');  // no cache
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', false);
header('Content-Type: application/pdf');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($filepath)) . ' GMT');
header('Content-Disposition: attachment; filename=' . urlencode(basename($filepath)));
header("Content-Transfer-Encoding:  binary");
header('Content-Length: ' . filesize($filepath)); // provide file size
header('Connection: close');
ob_end_clean();
readfile($filepath);
exit();
}