How reverse url works

I am trying to set up a simple traffic web application using php and am trying to fully understand how Callbacks URLs work. Based on my understanding, I have to provide a URL link to be inserted into the landing page form. After the visitor clicks the "Submit" button, the form values ​​will be posted (via POST) to the above link and monitored. After the transaction completes, the user is redirected back to the original page or any other page for example. Thank you, page. I believe this page is the actual callback url. Am I missing something in the above logic? Are there any php examples on how to accomplish the above task? thank.

receive.php

<?php
  if( $_GET["name"] || $_GET["age"] )
  {
     // DO YOUR STUFF;

     header( 'Location: http://www.yoursite.com/LandingPage.html' ); 
     exit();
  }
?>

      

LandingPage.html

<html>
<body>
  <form action="http://www.mytrack.com/receive.php" method="GET">
        Name: <input type="text" name="name" />
        Age: <input type="text" name="age" />
        <input type="submit" />
  </form>
</body>
</html>

      

+3


source to share


2 answers


It is right. The callback url will be called on a specific event. You should read the documentation for the callback tool.



As a workaround, you could write all the $ _POST and $ _GET array entries to a text file (fwrite) when the callback url is called to see what exactly is being passed to your script.

+1


source


The form is not necessarily POST

data. This will be the correct HTTP verb to use when saving data, but can also be used GET

with a form. This is defined using a property method

on the form element:

<form method="post" action="I-handle-forms.php">
    <!-- inputs, buttons, whatnots -->
</form>

      

The method you use also affects how you access data in PHP. GET

data is available in $_GET

, while POST

data is available in $_POST

. You can also use $_REQUEST

one that contains both data GET

and POST

, as well as any cookies that your site has sent.

Now, as for your question about user redirection, you do it with header()

:

header("Location: http://example.com/thank-you.php");

      

But again, this is not necessary to redirect the user. This makes sense most of the time, but you can also just show your thanks on the page the form is submitted to.



Remember, when invoked, there header()

must always be before anything else is sent to the browser. Even if the notification leaves the function call before header()

, the redirection doesn't work, so make sure you handle errors correctly.

Here's a good comparison of different verbs here . However, the rule of thumb is what GET

should be used to retrieve data, such as to perform searches, and POST

should be used when saving data such as registration. Parameters are GET

sent to a URL, so saving data from a call GET

can easily lead to meaningless database items.

So, if I understood your situation correctly, in that users submit data to save, you should use POST

. You can have a dedicated script form-processor.php

or so that the data is published. Check that the data is correct and save it in the database, if any. Then redirect the user to a thank you page or whichever page suits your use case. If the data is invalid, you can save the error messages in the user's session, redirect them back to the page with the form, and ask them to correct any errors in the submitted data. If you're not using sessions, you can easily pass data as parameters GET

by adding it to the redirect url:

header("Location: http://example.com/form.php?error=Invalid+email");

      

Remember to pass your parameters through first urlencode()

.

+1


source







All Articles