2

I had a simple php script as backend for my mobile app, There is an index.php and api.php , requests were sent to index.php, then index.php was sending a post request to api.php through cURL ( post request to https:///www.samplewebsite.com/service/api.php ) and printing the result from that.

Now the problem is, I had to change permissions for api.php, and it cannot be accessed via url. is there anyway to send post data to it without url? index.php and api.php are in same folder.

api.php is the php crud class (https://github.com/mevdschee/php-crud-api) it's kinda complicated class, so i didn't find it easy to modify it. I thought it might be better to not to touch that file, instead finding someway to send post requests with that.

4
  • 1
    add an extra parameter in index.php when you send the request to api.php. in api.php check if you have that specific parameter if not then send it to 404 page. You don't need to change the permission. Commented Mar 22, 2017 at 12:52
  • I have changed the permissions for API.php because it was accessible to public. Commented Mar 22, 2017 at 12:53
  • 1
    that is just alternate ... if you do that and if some one tries to open the api.php from browser it will redirect to 404 as it won't contain that specific parameter which you added in index.php Commented Mar 22, 2017 at 12:56
  • @MASIDDIQUI I got what you mean. Thanks Commented Mar 22, 2017 at 12:58

1 Answer 1

1

You can open the folder in terminal and make a server built-in in php.

cd /path/to/your/folder
php -S localhost:8888

Now you can make a request to localhost:8888/index.php or localhost:8888/api.php

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your answer, but i think it's not the solution for my problem. localhost:8888/api.php is still an URL
Hello Ataomega. But curls make requests. You can make a curl only for a http request, I believe. To get a file in your pc you can use the function file_get_content('/path/to/your/file');. Or I cannot understand your question ;D You want to get a file in your pc, right?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.