Eğer bir işlev çağrısı içinde bir PHP tanımlı değer arayabilir miyim?

2 Cevap

Aşağıda örnek kod bakmak bunu çalıştırdığınızda, tanımlanmış bir parçası başlık işlev çağrısında NotTranslated olduğunu lütfen, sözdizimi yapmak için özel bir yol var ya tam bu yöntem mümkün değil mi?

<?PHP
session_start();
define('SITE_URL', 'http://testsddf.com');
$_SESSION['user_role'] = 0;


//if a user is not active, redirect to verification/suspended page
if($_SESSION['user_role'] == 0){
    header('Location: SITE_URL');
}

?>

2 Cevap

Sen böyle bir şey yapamaz:

define('SITE_URL', 'http://testsddf.com');
header('Location: SITE_URL');

Bir sabit bir dize içinde, interpolasyon değildir: bu bir değişken (and you are using single-quote string, so it wouldn't work with a variable either, here) değil


You have to use string concatenation, in this situation :

define('SITE_URL', 'http://testsddf.com');
header('Location: ' . SITE_URL);


And, just to put a link to the manual as a reference, you can take a look at Variable parsing : there is nothing there about constants -- even if that's unfortunate.

Yapmanız gereken ya ...

header('Location: ' . SITE_URL);

... Ya ...

header("Location: SITE_URL");

... Tek tırnak gibi değişkenleri genişletmek değil. (this manual page daha fazla bilgi için bkz.)