Reputation: 2833
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
Upvotes: 5
Views: 16084
Reputation: 141829
Change:
<?php echo ''$_SERVER['PHP_SELF']'.logout=1' ?>
To:
<?php echo $_SERVER['PHP_SELF'], '?logout=1' ?>
Upvotes: 5
Reputation: 33432
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';"/>
Upvotes: 0
Reputation: 268344
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.
Upvotes: 1
Reputation: 1590
have you tried:
<?php echo($_SERVER['PHP_SELF'] . "?logout=1") ?>
Upvotes: 2
Reputation: 741
<a href="<?php echo $_SERVER['PHP_SELF'] . '?logout=1' ?>" id="add">
Upvotes: 2
Reputation: 32155
Your quotes are all over the place:
<a href="<?php echo $_SERVER['PHP_SELF'] . '?logout=1'; ?>" id="add"><input type="button" value="LOGOUT" /></a>
Upvotes: 1