tango4567 / solutions

Here I am adding lots of different stuff. This is the collection of problems with their solutions. Most important please share good vibes and correct me if you found anything wrong here. Thanks in advance.
Apache License 2.0
5 stars 0 forks source link

Php post request issue #28

Closed tango4567 closed 3 years ago

tango4567 commented 3 years ago

Why I'm getting empty array all the time. Please suggest me whats wrong in this below code:

<?php
function validateEmail($checkEmail){
    return filter_var($checkEmail, FILTER_VALIDATE_EMAIL);
}

$email = isset($_POST["emails"]) && is_array($_POST["emails"]) ? $_POST["emails"] : [];
$validateEmail = 'validateEmail';
$sorted_emails = array_filter($email, $validateEmail);

header("Content-Type: application/json");
echo json_encode($sorted_emails);
?>
tango4567 commented 3 years ago

Basically after doing some studies with help of $_POST and PHP Cookbook then i realized my sily mistake, if we use $_POST in index.php then we need to define full path including index.php then on $_POST variable work other wise it always return empty as mentioned in above problem. So I just gave path. :heavy_multiplication_x: https://tarunmahajan.com/api/email :heavy_check_mark: https://tarunmahajan.com/api/email/index.php

I hope this will help and I request you if found any mistake with this explantion please correct me Thank you.