I have error when send data to database.
First I have URL like:
www.domain.com/container.php?fun=olmaa
and after send data, the URL is as below:
www.domain.com/container.php?fun=olmaa&sent=yes
But, when send again it looks like:
www.domain.com/container.php?fun=olmaa&sent=yes&sent=yes
Why insert &sent=yes
again ??
My code is:
$url = "http". ((!empty($_SERVER['HTTPS'])) ? "s" : "") . "://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
header('Location: '.$url."&sent=yes");
Thank You
Before appending sent param just check it already exist or not by strpos
. Try this..
$url = "http". ((!empty($_SERVER['HTTPS'])) ? "s" : "") . "://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
$final_url = (strpos($url, '&sent=yes') == false) ? $url."&sent=yes" : $url;
header('Location: '.$final_url);
Or can use parse_str
.
$url = "http". ((!empty($_SERVER['HTTPS'])) ? "s" : "") . "://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
parse_str($url, $params);
$final_url = (!isset($params['sent'])) ? $url."&sent=yes" : $url;
header('Location: '.$final_url);
The problem is that the second time you try to send the data the url that you are sending them is
www.domain.com/container.php?fun=olmaa&sent=yes
So when you are building the new url in the $_SERVER['REQUEST_URI'] already exists the &sent=yes part and you are appenting it again thats why you see it two times. The code user3659034 gave solves it.