• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Not getting Get Variables form Url

#1
[eluser]kalpesh[/eluser]
Hi,
I try to get variables from Url which like as follow

http://localhost/Site/index.php/Offer?City=NewYork&Id=1

and try to print that variables
Code:
$data['city']=$_GET['City'];
  $data['pid']=$_GET['Id'];
  echo $data['pid'];
   echo $data['city'];

But I get this error:
Code:
A PHP Error was encountered
Severity: Notice

Message: Undefined index: City

Filename: controllers/Offer.php

Line Number: 15

A PHP Error was encountered
Severity: Notice

Message: Undefined index: Id

Filename: controllers/Offer.php

Line Number: 16

I am just new in CI.
So please Help me.
Thanks.

#2
[eluser]pistolPete[/eluser]
User guide:
Quote:GET data is simply disallowed by CodeIgniter since the system utilizes URI segments rather than traditional URL query strings (unless you have the query string option enabled in your config file). The global GET array is unset by the Input class during system initialization.

#3
[eluser]xwero[/eluser]
The basics of using the GET global is to set the uri_protocol to PATH_INFO, PATH_INFO_ORG or REQUEST_URI.
If you want to enable query strings globally you set enable_query_string to true, or if you only want to use it for a few methods you add following as the first line of the method
Code:
$_GET = parse_str($_SERVER['QUERY_STRING']);

#4
[eluser]xwero[/eluser]
pistolPete your comment is not really helpful as as you see from my response it's very easy to circumvent the GET destruction of CI.

#5
[eluser]pistolPete[/eluser]
Well, kalpesh said he is new to CI.
That's why I thougt I'd show him how CI usually handles URL parameter.
It did not seem to be required to use GET variables, he only wanted to pass some parameters to his controller.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.