In PHP, the $id variable should receive an integer value from the client. However, when the client sends the id value as an integer to the PHP script using the POST request method, it is automatically converted to the string type in PHP when the script is uploaded to the WAMP server. On the other hand, when the script is uploaded to the Bluehost server, the id values are still integers and are not converted to strings, which is what I want.
This is a simple PHP script:
<?php $id = $_POST["id"]; if (is_int($id)) echo "It is integer"; // It will print this if the PHP script was uploaded to the Bluehost server. else if (is_string($id)) echo "It is string"; // It will print this if the PHP script was uploaded to the WAMP server.
The id value sent from the client is sent through the Android application, this is how I send the id value to the PHP script:
RetrofitManager class
public class RetrofitManager { private static RetrofitManager.Api api; public static RetrofitManager.Api getApi() { if (api == null) api = new Retrofit.Builder() .baseUrl("http://192.151.5.721/API/") .client(new OkHttpClient.Builder().readTimeout(3, TimeUnit.MINUTES).writeTimeout(3, TimeUnit.MINUTES).connectTimeout(25, TimeUnit.SECONDS).build()) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJava3CallAdapterFactory.create()) .build() .create(Api.class); return api; } public interface Api { @FormUrlEncoded @POST("Countries/Get.php") Single<CountryModelResponse> getCountries(@Field("id") int countryId); } }
CountriesRepository Class
public class CountriesRepository { public LiveData<Object> getCountries(Context context) { MutableLiveData<Object> mutableLiveData = new MutableLiveData<>(); PublishSubject<String> retrySubject = PublishSubject.create(); RetrofitManager.getApi().getCountries(Navigation.findNavController(MainActivity.activityMainBinding.activityMainFragmentContainerViewContainer).getPreviousBackStackEntry() == null ? SharedPreferencesManager.getIntegerValue(context, SharedPreferencesManager.Keys.COUNTRY_ID.name()) : -1) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe(mutableLiveData::setValue) .doOnError(throwable -> { LinkedHashSet<Object> linkedHashSet = new LinkedHashSet<>(); linkedHashSet.add(!Utils.isInternetConnected(context) ? 100 : throwable instanceof SocketTimeoutException ? 200 : 300); linkedHashSet.add(retrySubject); mutableLiveData.setValue(linkedHashSet); }) .retryWhen(throwableFlowable -> throwableFlowable.flatMap(throwable -> retrySubject.toFlowable(BackpressureStrategy.DROP).take(1), (throwable, s) -> s)) .subscribe(countryModelResponse -> { if (countryModelResponse.getRequestStatus() == 100) mutableLiveData.setValue(countryModelResponse); else { LinkedHashSet<Object> linkedHashSet = new LinkedHashSet<>(); linkedHashSet.add(300); linkedHashSet.add(retrySubject); mutableLiveData.setValue(linkedHashSet); } }); return mutableLiveData; } }
I'm not sure why this difference in behavior occurs between the two servers.
I'm using the latest version of PHP and WAMP server.
All requests over HTTP are sent as strings. We have to mold it to our needs. In your case, the behavior is strange. Try checking if the PHP version is the same on both ends.