0

I have created a simple API service for my login page which posts data to my API using cURL and that works but in my API index I keep getting an error:

undefined index username

<?php
  header('Content-Type: application/x-www-form-urlencoded');
  $username = $_GET['username'];
  $password = $_GET['password'];

but when i hard code it into the url http://www.example.com/LoginApi/index.php?username=gerald&password=4321 it works

Gerald Mathabela
  • 475
  • 2
  • 4
  • 16
  • 1
    Most probably because $_GET is empty – Pavel Janicek Feb 19 '17 at 20:20
  • 1
    Possible duplicate of [PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef) – Pavel Janicek Feb 19 '17 at 20:22
  • but when i hard code the variables into the url eg: http://www.example.com/LoginApi/index.php?username=gerald&password=4321 it works only when i'm running it via the REST client it returns the above error... – Gerald Mathabela Feb 19 '17 at 20:23
  • when you hard code it then the variable is populated –  Feb 19 '17 at 20:27
  • Show the code where you are calling it through Rest client – Pavel Janicek Feb 19 '17 at 20:32
  • useCURL($userData, $apiUrl); and this goes through custom global curl class that i created... find it at https://github.com/Gerald34/Global-cURL – Gerald Mathabela Feb 19 '17 at 20:34

0 Answers0