The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex
Your question is a bit vague, but I think you're looking for something along the lines of:
ReplyDeletesession_start();
if (isset($_SESSION['number'])) { /* If there is already a value set */
$_SESSION['number']++; /* Increment by 1 */
}
else { /* If there is no value set, ie the user is clicking the button for the first time */
$_SESSION['number'] = 1; /* Set to 1 */
}
All you need to do is increment the value in the $_SESSION array:
ReplyDeletesession_start();
$_SESSION['no'] = empty($_SESSION['no']) ? 0 : $_SESSION['no'];
$_SESSION['no'] += 1;
Using session_register is DEPRECATED as of PHP 5.3.0
ReplyDelete<?php
session_start();
$_SESSION['count']=(isset($_SESSION['count']))?$_SESSION['count']+1:0;
?>
The main issue is how you're incrementing your variable. PHP does not default to assigning variables by reference, so $_SESSION['sess_id'][] = $no; is actually assigning by value (in addition to indexing the variable as an integer). Your subsequent call $n++ won't alter the value stored in your PHP session.
ReplyDeleteWhat I think you want is to assign by reference, e.g.
$no = 1;
session_start();
$_SESSION['your_session_var_name'] =& $no; // value is '1'
$no++; // $no is now '2'
echo $_SESSION['your_session_var_name']; // outputs '2'
Do not use session_register anymore, just use the $_SESSION array.
ReplyDeletesession_start();
if(!isset($_SESSION['sess_id'])) $_SESSION['sess_id'] = 0;
$_SESSION['sess_id']++;