1

I'm using $_REQUEST to get sent data to a page and page will return me some value, but right now only if i send data with GET, page will return me data And I need to send request with POST method.

This is the domain that i send request to: http://rapapp.mobi
example request: http://rapapp.mobi/?Slides=4

I have changed request_order in php.ini to both request_oder="GP" & request_order="PG" and tried but no luck!

Note:
If you send request to that domain with GET you will be redirected to another domain with same request but if you send request to that domain in POST you will be redirected to website index.

very specific: TCP port is open, if you send request to main domain on server both methods work. (Main domain: http://rapfarsi.com). And this problem started when i moved web files from Host to VPS.

Please help me whats going on? i need to send request with POST method

One of my functions that will return data

    add_action('init' , 'Singles');
function Singles(){

if(!isset($_REQUEST['Singles'])) return;


$limitation = (int) $_REQUEST['Singles'];

$json = array();
header('Content-Type: application/json');
$args = array(
'cat' => 111,
'posts_per_page' => $limitation
);
// The Query
$the_query = new WP_Query( $args );

// The Loop
if ( $the_query->have_posts() ) {

while ( $the_query->have_posts() ) {

$img = wp_get_attachment_url( get_post_thumbnail_id(get_the_ID) );
$the_query->the_post();
$json[] = array(
'id' => get_the_ID(),
'title' => get_the_title(),
'isSingle' => in_category(111,null),
'link' => get_the_permalink(),
'image' =>  wp_get_attachment_url(get_post_thumbnail_id(get_the_ID()))
);

}
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();

echo '{"items":'.json_encode($json).'}';

die();
}
Ali Akhgar
  • 101
  • 1
  • 10

2 Answers2

0

I believe that the fastest way to resolve this problem is to override the default $_REQUEST values with a manual merge of $_GET and $_POST.

At the top of your app, or in the initializer script write the follow.

$_REQUEST = array_merge($_GET, $_POST);

Some PHP Frameworks use that way.

Claudio King
  • 1,606
  • 1
  • 10
  • 12
0

@Claudio King

I think even PHP uses $_REQUEST to store both $_GET and $_POST array values, means whatever you can access with $_GET or $_POST, you can access the same with $_REQUEST.

means if

$_GET['name'] = 'test' then $_REQUEST['name'] is also = 'test'

and same goes with $_POST

$_POST['name'] = 'test' then $_REQUEST['name'] is also = 'test'

Shashank
  • 425
  • 5
  • 10
  • yeah, what you said is true, Whats your suggestion? – Ali Akhgar Sep 17 '16 at 19:01
  • Hello Ali Nice to hear back from you. how are you posting data on your page? i think you should try to Post data with PHP Curl Request set POST data and fire a request. and on Page open you should check for the POST variable isset or not like isset($_POST['Slides']) and if Post data is set then you should proceed with Reverting the Data as you are sending in GET request, and if is not set then you should open the Site Page. but why you need to Revert Data from index page of your website? means you can use a seprate page like api.php for Reverting the API Data... – Shashank Sep 17 '16 at 19:39
  • BTW you built a nice website – Shashank Sep 17 '16 at 19:42
  • thanks, right now i was testing with Postman chrome addon, so i sent a simple post request to that url and worked perfectly, try it your self. god whats going on? – Ali Akhgar Sep 17 '16 at 19:56
  • Hello Postman has some issues with POST parameter, i tested it myself. Also Refer the URL http://stackoverflow.com/questions/24168759/sending-post-parameters-with-postman-doesnt-work-but-sending-get-parameters-do and please Try this http://requestmaker.com/ i tested it currently and it worked. – Shashank Sep 17 '16 at 20:10
  • In requestmaker.com just dont set and Header and Delete the value text/html field and in Request Data: use Slides=4 – Shashank Sep 17 '16 at 20:11