else if ifadeleri php

3 Cevap php

Ilk sayfasına gittiğinizde Bunu nasıl göstermek değil alabilirim??

if ($error) {
 echo "Error: $error<br/>";
}
if ($keycode) {
 echo "Keycode: $keycode<br/>";
}

3 Cevap

<?php
session_start();

if ($_SESSION['been_here'] == true) {
     // show what you need to show
}
else {
    // don't show it
    $_SESSION['been_here'] = true;
}
?>

The point here is that $_SESSION-variables "last" (as long as you session_start()). Google "php sessions" for more information, and ask more questions on SO if necessary. :)

Session_destroy () kullanın; oturumu yok etmek.

Açıklamalara dayanarak, bunu bekliyoruz önce koşullu true değerlendirmek gibi görünüyor. Kodunuzun daha görmeden, bu sadece bir tahmin olduğunu, ancak ben senin sorun değişkeni bunu yanlış anlamına gelmez ki yaratmak $error varsayılan / geçici bir değer veriyoruz olduğuna inanıyorum. Örneğin:

$error = "default error message, change me later";

// Later...
if ($error) { // This evaluates to true
    echo "Error: $error<br/>";
}

Eğer öyleyse, PHP's documentation on casting to booleans check out, ve belki de (Christian's answer katkısıyla) böyle bir şey kullanmak isteyeceksiniz:

$error = "0"; // Default error message, change it later

// Later...
if($_SESSION['been_here'] == true)
    $error = "This is the real error message.";

// Even later...
if ($error) {
    echo "Error: $error<br/>";
}

Bu muhtemelen sizin için çalışıyor:

if (isset($error) && !empty($error)) {
     echo "Error: $error<br/>";
}

Eğer değeri $error ne olabileceğini belirtilmiş değil, çünkü daha fazla söyleyemem.

Yoksa sadece bir hata oluştuğunu belirten bir bayrak tanıtmak zorunda:

$error = 'Error message.';
$has_error = false;

if(!empty($_POST) && some_condition) { // means it is a POST request
    $has_error = true;
}

if($has_error) {
    echo "Error: $error<br/>";
}