PHP使用添加的变量回显$ _SERVER ['PHP_SELF']?

Just want to do $_SERVER['PHP_SELF'] as a link with ?logout=1 appended to it.

<a href="<?php echo ''$_SERVER['PHP_SELF']'.logout=1' ?>" id="add"><input type="button" value="LOGOUT" /></a>

gives

Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in F:\export\srv\www\vhosts\main\htdocs\php\assign3\m_a2_functions.php on line 90

Change:

<?php echo ''$_SERVER['PHP_SELF']'.logout=1' ?>

To:

<?php echo $_SERVER['PHP_SELF'], '?logout=1' ?>

Your quotes are all over the place:

<a href="<?php echo $_SERVER['PHP_SELF'] . '?logout=1'; ?>" id="add"><input type="button" value="LOGOUT" /></a>
<a href="<?php echo $_SERVER['PHP_SELF'] . '?logout=1' ?>" id="add">

have you tried:

<?php echo($_SERVER['PHP_SELF'] . "?logout=1") ?>

This may be a place where printf() would come in handy.

<a href="<?php printf( '%s?logout=1', $_SERVER['PHP_SELF'] ); ?>">Foo</a>

This cuts down on the number of times we hop in and out of a string.

You are defining an anchor (<a>) and putting a button inside it, but the button will not send you to that url. You should make the "onclick" event of the button redirect the user to the page you want.

Also, if you just want to add a variable to the current URL you don't really need to use PHP_SELF, the browser will know what to do.

<input type="button" value="LOGOUT" onclick="window.location.href='?logout=1';"/>