Jump to content
php.lv forumi

!nenostrādā Back poga..


raivis

Recommended Posts

!?Kā lai uz php uzdabūju:

  • 1..lai nenostrādātu Back poga=> header("location: $REQUEST_URI");
  • ---
  • 2..uzspiežot Back=> session_destroy();

 

session_start();

header("Cache-control: private");

 

if(@$_SESSION['user']) { header("location: index.php?id=login"); }

..

 

JavaSriptā var izmantot:

//lock
if (document.all){
  document.onkeydown = function (){
     var key_f5 = 116; // 116 = F5
     if (key_f11==event.keyCode){
        alert("F5 pressed");
        return false;
     }
  }
}
function showDown(evt) {
evt = (evt) ? evt : ((event) ? event : null);
 if (evt) {
 if (event.keyCode == 8 && (event.srcElement.type != "text" && event.srcElement.type != "textarea" && event.srcElement.type != "password")) {
// When backspace is pressed but not in form element
cancelKey(evt);
}
  else if (event.keyCode == 116) {
// When F5 is pressed
cancelKey(evt);
}
  else if (event.ctrlKey && (event.keyCode == 78 || event.keyCode == 82)) {
// When ctrl is pressed with R or N
  cancelKey(evt);
}
}
}
function cancelKey(evt) {
 if (evt.preventDefault) {
  evt.preventDefault();
  return false;
  }
   else {
    evt.keyCode = 0;
    evt.returnValue = false;
   }
 }
// Additional code for NS
  if (navigator.appName=="Netscape") {
   document.addEventListener("keypress",showDown,true);
  }
   document.onkeydown  = showDown;

bet tas nav gluži tas, ko vēlētos..

Link to comment
Share on other sites

1) Back poga strādā neatkarīgi no tava php skripta. Browseris pats var izdomāt, kad pieprasīt vai nepieprasīt datus

2) JavaScript vienmēr var atslēgt, tāpēc kāda jēga pūlēties kautko aizliegt, ja to var elementāri atslēgt?

Link to comment
Share on other sites

un priekš kam tas vajadzīgs?

 

session_start();

if (!isset($_SESSION['visited']))

$_SESSION['visited']=array();

if (!in_array($_SERVER['QUERY_STRING'],$_SESSION['visited']))

$_SESSION['visited'][]=$_SERVER['QUERY_STRING'];//primo reiz

else

{

//otro reiz

header(...);

exit;

}

Link to comment
Share on other sites

Izmantojot:

session_start();

if (!isset($_SESSION['user']))

$_SESSION['user']=array();

if (!in_array($_SERVER['QUERY_STRING'],$_SESSION['user']))

$_SESSION['user'][]=$_SERVER['QUERY_STRING'];//primo reiz

else

{

//otro reiz

header(...);

exit;

}

man gļuko lapu - uzrādot, ka kļūda ir rindā:

if (!in_array($_SERVER['QUERY_STRING'],$_SESSION['user']))

Link to comment
Share on other sites

!nenostrādā..

session_start();
header("Cache-control: private");

if(!isset($_POST['user']) && !isset($_SESSION['user']) && !isset($_POST['pass']) && !isset($_SESSION['pass'])) {
echo "<form action=\"\" method=\"POST\">
Login:<input type=\"text\" name=\"user\"><br>
Pass:<input type=\"password\" name=\"pass\"><br>
<input type=\"submit\" value=\"Login\">
</form>";
} else {
echo "<a href=\"javascript:window.location=window.location\">Refresh</a> ";
if(@$_SESSION['user'] && @$_SESSION['pass']){
 echo "<a href=\"?id=logout\">Logout</a><hr>ok! ".$user." ".$pass; //header('location: index.php?id=login');
 } else {
  $_SESSION['user']=array();
  $_SESSION['pass']=array();
  $_SESSION["name"]              = $name;
  $_SESSION["surename"]          = $surename;
  $_SESSION["user"]              = $user;
  $_SESSION["pass"]              = $pass;
    if (!in_array($_SERVER['QUERY_STRING'],@$_SESSION['user'] && @$_SESSION['pass'])) {
     @$_SESSION['user'] && @$_SESSION['pass'][]=$_SERVER['QUERY_STRING'];
    } else {
     header("locarion: index.php");
     exit;
    }
 }
}
if ($id==logout) {
if(@$_SESSION['user'] && @$_SESSION['pass']){
 $_SESSION["name"]              = false;
 $_SESSION["surename"]          = false;
 $_SESSION["user"]              = false;
 $_SESSION["pass"]              = false;
 session_destroy();
}
echo "<br>You are <b>logout!</b>"; //header('location: index.php?id=logout');
}
Link to comment
Share on other sites

up close & personal jautājiens ;)

 

no redzētā:

 

if(@$_SESSION['user'] && @$_SESSION['pass']){

echo "<a href=\"?id=logout\">Logout</a><hr>ok! ".$user." ".$pass;

 

$user un $pass iepriekš nav definēti

arī tālāk:

$_SESSION["name"] = $name; ...

neredzu no kurienes tie rodas

 

(!in_array($_SERVER['QUERY_STRING'],@$_SESSION['user'] && @$_SESSION['pass'])

 

ko atrgiež (array() && array()), manuprāt false vai true, ja abos masīvos kaut kas bijis, bet nu nekādīgi ne kopmasīvu, ar + vēl varbūt, tomēr tik un tā - no kurienes tur query_stringam rasties?

 

NB: you are logged out

 

@$mainigais vietā vēlams izmantot !empty($mainigais)

Link to comment
Share on other sites

×
×
  • Create New...