Thursday, November 24, 2016

$_GET &_POST $_REQUEST

$_GET &_POST $_REQUEST বিষয় টা  কি ?
  1.  কোন input এ যদি name সেট করা হয়, input এ কিছু লিখে submit করা হয় 
EX  :

    

input এ যদি ami লিখি তাহলে show করবে http://localhost/project/php/?uiui=ami . এটা name সেট করার জন্য হয়। WordPress  এ same কাজ করে।
CODE ১:

   
   
   
   
   
   
   

SHOW :
http://localhost/project/php/?name=ranit&email=rntprince%40gmail.com&number=01739463581
লিংক এ @ না হয়ে %40 শো করে।
form এ যদি method GET use করতাম তাহলে same কাজ করতো। GET টা হলো ডিফল্ট।
কিন্তু যদি POST use করি তাহলে শো করবে না. এটা secured . এখানে get post request small latter হলেও কোনো problem নাই।
তাই get use করলে link এ query use করে user information বাহির করতে পারবে।
তাই আমরা post use করবো।
SHOW করবো কি ভাবে :
FOR ১ 
TYPE  ONE 
  echo $_POST['name']."";
  echo $_POST['email']."";
  echo $_POST['number']."";

যদি  echo $_POST use করি array show করবে। কারণহলো value গুলো array আকারে জমা হয় ।
EX :
 print_r($_POST); use করলে
show  করবে।

TYPE  TWO 
[ ] use না করে
 foreach($_POST as $kjkk){
     echo $kjkk."";
   
 };


request টা  কি?
পোস্ট আর জায়গাতে request use করা যায়। 
  • You should use $_GET when someone is requesting data from your application.
  • And you should use $_POST when someone is pushing (inserting or updating ; or deleting) data to your application.
$_REQUEST is supposedly (or at least used to be) more expensive than using $_POST and $_GET directly.
  • $_GET retrieves variables from the querystring, or your URL.>
  • $_POST retrieves variables from a POST method, such as (generally) forms.
  • $_REQUEST is a merging of $_GET and $_POST where $_POST overrides $_GET. Good to use $_REQUEST on self refrential forms for validations.


ফাইল করা :
 একটা file.php  তৈরী করলাম। কোড:
$showingone = $_REQUEST['name'];
$showingtwo = $_REQUEST['email'];
$showingthree = $_REQUEST['number'];

echo "Name: ".$showingone."";
echo "Email Id: ".$showingtwo."";
echo "Contact Info: ".$showingthree."";




 ইনপুট submit করার পর file.php তে যাবে 
 এটা show করবে। 

problem :
দুই form but file একটা। 
solve :



   
   
   
   
   
   
   

   
   
   


file.php তে 

 if(isset($_REQUEST['name'])){
     $showingone = $_REQUEST['name'];
 }
 if(isset($_REQUEST['email'])){
    $showingtwo = $_REQUEST['email'];
 }
 if(isset($_REQUEST['number'])){
     $showingthree = $_REQUEST['number'];
 }


if(isset($_REQUEST['one'])){   
    echo "Name: ".$showingone."";
    echo "Email Id: ".$showingtwo."";
    echo "Contact Info: ".$showingthree."";
}
else{
    echo $_REQUEST['search']."";
   
}


যদি file.php তে show করতে চাই যে Email has been sent তখন file.php তে
if(isset($_REQUEST['one'])){
mail($showingtwo, $showingone, $showingthree);
echo "Email has been sent";
} তা use করতে হবে।
PROBLEM :
XAMPP server এ যদি warning  show করে solve
link : http://stackoverflow.com/questions/15965376/how-to-configure-xampp-to-send-mail-from-localhost

You can send mail from localhost with sendmail package , sendmail package is inbuild in XAMPP. So if you are using XAMPP then you can easily send mail from localhost.
for example you can configure C:\xampp\php\php.ini and c:\xampp\sendmail\sendmail.ini for gmail to send mail.
in C:\xampp\php\php.ini find extension=php_openssl.dll and remove the semicolon from the beginning of that line to make SSL working for gmail for localhost.
in php.ini file find [mail function] and change
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = my-gmail-id@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
Now Open C:\xampp\sendmail\sendmail.ini. Replace all the existing code in sendmail.ini with following code
[sendmail]

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=my-gmail-id@gmail.com
auth_password=my-gmail-password
force_sender=my-gmail-id@gmail.com
Now you have done!! create php file with mail function and send mail from localhost.
PS: don't forgot to replace my-gmail-id and my-gmail-password in above code. Also, don't forget to remove duplicate keys if you copied settings from above. For example comment following line if there is another sendmail_path : sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe" in the php.ini file
Also remember to restart the server using the XAMMP control panel so the changes take effect.

আমি এই problem face করছি and solve করেছি। কিন্তু live server ছাড়া mail আপনার email এ যাবে না। এটা possible না। কারণ XAMPP হলো home server .

SUBSCRIBE:

 আমি চাই কেউ subscribe করলে email এ message তা যাবে এবং index.php তে message show করবে।


send.php তে code :

if(isset($_REQUEST['subscribe'])){
    if(isset($_REQUEST['email'])){
        $email = $_REQUEST['email'];
        mail('rntprince@gmail.com', 'This is a subscribe message', $email);
        header("Location: index.php?thanksforyoursuccessfulsecscribsion");
    }
}









1 comment: