1

I have been developing a PHP page using Code Igniter. There is some function from controller:

public function language_testing($language_code, $logout=0)
{      
      echo ($language_code);
      //come actions
}

And I'm trying to send the following url: http://mypage.com/index.php/controller/language_testing/bg#9

But my function shows me "bg" instead of "bg#9". Please, tell me, how can I get a content after "#"? I need it so much.

user1538002
  • 57
  • 1
  • 5

5 Answers5

1

You should be posting to the following URL to get the value to appear in $logout:

http://mypage.com/index.php/controller/language_testing/bg/9

Otherwise, the data after the pound sign isn't accessible by the server.

nickb
  • 59,313
  • 13
  • 108
  • 143
1

http://au.php.net/manual/en/function.parse-url.php

$urlComp=parse_url($yourURL);
echo $urlComp['fragment'];
varuog
  • 3,031
  • 5
  • 28
  • 56
0

You can't. The # is a HTML bookmark, used to redirect focus around a page using IDs on HTML elements. Browsers won't submit this as part of a URL to the server.

Depending on your rewrite rules, you'll either want to create a link that's semantically pleasing, like http://site.com/path/index.php/bg/9 or as http://site.com/path/index.php?bg=9 (which is what your rewrite rules would be achieving anyway).

Note if you really need the # sign to be submitted for some reason then you'll need to submit it using %23 in the URL (@jth_92 beat me to it).

Rhys
  • 1,439
  • 1
  • 11
  • 23
0

You need to alter the function params add one more parameter for code as well

public function language_testing($language, $code , $logout=0){      
  echo ($language);
  echo ($code);
  //come actions

}

and call it just like http://mypage.com/index.php/controller/language_testing/bg/9

it will resolve your problem and then you can concatenate both values

Suleman Ahmad
  • 2,025
  • 4
  • 28
  • 43
0

The # is an HTML entity that is used in anchor tags to jump to a name reference. For example:

<a href="#test">Jump to test on page</a>
<a name="test">Test</a>

Thus, it is not being interpreted as part of your parameter. You should be able to use bg%23 as %23 is the escape character for hashing.

http://mypage.com/index.php/controller/language_testing/bg%239

How to escape hash character in URL

Community
  • 1
  • 1
jth_92
  • 1,120
  • 9
  • 23