-1

i want to create a link like the below:

<a href="'.$_SERVER["REQUEST_URI"].'?&action=approve&holiday='.$result["sequence"].'">

the $_SERVER["REQUEST_URI"] includes any $_GET variables already set, but i am not sure whether to put a ? or & after this in the href because $_SERVER["REQUEST_URI"] could already include a $_GET variable therefore it would need & and not a ?

4
  • i cant see where this helps with adding either ? or & Commented Jul 28, 2016 at 18:43
  • I think you would have to check $_SERVER["REQUEST_URI"] content, in order to see if it already contains any GET variables. For example: if ($_SERVER["REQUEST_URI"] contains '?') then you use "&" to include your content, if not then you can use "?". Something like that? Commented Jul 28, 2016 at 18:46
  • 1
    See this previous post stackoverflow.com/questions/7864237/… Commented Jul 28, 2016 at 18:47
  • Use my updated answer Commented Jul 28, 2016 at 18:57

2 Answers 2

1

Check if it includes '?' or not.

$extra = 'action=approve&holiday='.$result["sequence"];
$glue = (strpos($_SERVER["REQUEST_URI"], '?') === false) '?' : '&';

Then, you can use this:

 echo '<a href="'.$_SERVER["REQUEST_URI"]. $glue . extra .'">';

But, if you don't need the current passed parameters in URL, you can use the way @Utkanos said

Sign up to request clarification or add additional context in comments.

1 Comment

Exactly what I thought :)
0

You need to build the URL in parts. All of the data you need is contained in the $_SERVER superglobal.

$_SERVER['REQUEST_SCHEMA'].'://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'//...

PHP_SELF denotes the URI beyond the hostname, e.g. "/foo/bar.htm" in "mydomain.com/foo/bar.htm"

http://php.net/manual/en/reserved.variables.server.php

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.