For example: I declared url in javascript:
<script>
window.location.href = "signup.php#year=" + myyear;
</script>
And in php, I am trying to get #year:
<?php
if(isset($_GET['year'])){
$year = $_GET['year'];
}
?>
thank you in advance!
For example: I declared url in javascript:
<script>
window.location.href = "signup.php#year=" + myyear;
</script>
And in php, I am trying to get #year:
<?php
if(isset($_GET['year'])){
$year = $_GET['year'];
}
?>
thank you in advance!
don't used # sign
<script>
var myyear;
window.location.href = "signup.php?year=" + myyear;
</script>
and you can get
<?php
if(isset($_GET['year'])){
$year = $_GET['year'];
}
?>
Actually you just missing one thing on your href.
window.location.href = "signup.php?year=" + myyear
this code results to url with *signup.php?year=2017
Php
You can get it using $_GET['year'] now.
Convert the url string to a PHP url object with the function parse_url and dereference its "fragment" key like this:
$url=parse_url("www.example.com/example/?shareURL&adherentID=ascd#123");
echo $url["fragment"];
The above code returns 123. working example here - http://codepad.org/r8icljcW
If you want to make use of $_GET then you should use a ? instead of #. The ? symbol is the indicator for a GET, not the #.
So simply change your URL structure to:
<script>
window.location.href = "signup.php?year=" + myyear;
</script>
and then, as you already did, grab the value with the GET.
<?php
if(isset($_GET['year'])){
$year = $_GET['year'];
}
?>
If you want to use more parameter, use the &symbol to separate them. You can add as many as you want, you just have to follow the `&key1=value1&key2=value2? structure and you can expand it as long as you want. Example:
<script>
window.location.href = "signup.php?year=" + myyear&month=5;
</script>
Now you could do:
<?php
if(isset($_GET['year'])){
$year = $_GET['year'];
$month = $_GET['month']; // Would assign 5 to month.
}
?>