1

Can Someone help me.

I have a link like this:

http://www.somesite.com/somepage.php?&validation=3545&validation=1431

but i want to get the 1431 from the second validation as a variable. I tried to use this but it didn't work:

$Validationcode2 = $_GET['validation=3545&validation'];

But i think it doesn't works that way.

7
  • 1
    Parameter names should be unique. Do you have control over URL? Commented Dec 21, 2015 at 22:07
  • Do you mean this: http://www.somesite.com/somepage.php?validation=3545&validation=1431 (Removed extra ampersand) Commented Dec 21, 2015 at 22:09
  • 2
    Possible duplicate of How to get multiple parameters with same name from a URL in PHP Commented Dec 21, 2015 at 22:10
  • 1
    no, each validation should be unique (validation1=3545&validation2=1431) Commented Dec 21, 2015 at 22:10
  • 3
    Or use an array validation[]=3545&validation[]=1431 Commented Dec 21, 2015 at 22:11

3 Answers 3

1

You'll want the GET parameters to be unique, so don't have two validation variables, assuming that was a mistake:

If you know the name you can reference it like:

$second_param = $_GET["validation"];

If you always want the second variable regardless of name you could do it like this:

$key_array = array_keys($_GET);
$second_param = $_GET[$key_array[1]];
Sign up to request clarification or add additional context in comments.

Comments

1

Use $_SERVER['QUERY_STRING'] to get the entire query string. Then you can apply a regex (try /[?&]validation=3545&validation=(\d*)/) to get the value you're looking for.

Regex demo: http://www.phpliveregex.com/p/e1L

$_SERVER documentation: http://php.net/manual/en/reserved.variables.server.php

Comments

0

It's definitely better to use the validation[] construct but the funny thing is that it actually works out to print the second parameter of &validation=1431

$url = "http://www.somesite.com/somepage.php?&validation=3545&validation=1431";
$parsed_url = parse_url($url);
$query = $parsed_url['query'];
parse_str($query,$parts);

print_r(array('parts'=>$parts));

this prints out

Array(
    [parts] => Array(
        [validation] => 1431
    )
)   

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.