Above person search php submit. PHP _SELF in action form attribute. Detailed contact search

Golovna / Korisne PZ

Author ID: PHP-script to ask for an unknown part of the current resource. Ale for rozrobnikiv-pochatkіvtsіv yogo implementation can become an “external stone”. Today, I'll try to explain why such a module can be simpler, so that the code does not slander you with its transcendental folding.

Shukaemo in PHP

Organization on the site of the internal system for a request for important tasks. The presence of such a functional significantly raises the resource in the eyes of a koristuvach. Vuzkotematichnyh sites, the content of such assignments to specific problems, are especially valued. For example, in web programming.

The most common way to write a script is to search the site in PHP using the language of this software movie. For the implementation of interactive poke system zastosovuetsya technology AJAX. But today we are not “winding” in such netry, and we are singling on the classic version.

I will bring the simplest example of a joke. There will be no re-verification of the visibility of the database management system, re-verification of the results of the selection, what to turn, and so on. You can add all these subtleties on your own. Meta material - dates publicity about the prompt of the internal system, I will ask on the current Internet resource. Let's go!

I'll put the form code on the back for the introduction of a per-click request. This is a simple layout, navit without the least stylistic “vishukuvan”.




< form name = "f1" method = "post" action = "search.php" >

< input type = "search" name = "search_q" / > < / br >

< / br >

< input type = "submit" value = "Poshuk" / > < / br >

< / form >

This is how the form looks in the browser:

Let's go to the script

Now let's go straight to the program code. I will put the structure of the table in reverse order, as it is necessary to create in . We are happy to publish materials under their heading. Following this principle, you can create a PHP script to search for links on the site. Everything is in your gentle hands.

On the back of my hand, we change the meaning, introduced the short form. Let's clean up yoga like "smіttya": zayvih clearings, tags and connect to the base. After which it is launched SQL query, in a way similar to the value of the search request for the name of the materials, saving tables. When zbіgu vyvodimo vidpovіdny content. Nasamkіnets zakrivaєmo z'єdnannya z MySQL and "skidaєmo" request. Axis all code will apply:

$search_q = $_POST["search_q"];

$l = mysqli_connect("localhost", "root", "", "site");

$search_q = trim($search_q);

$search_q = strip_tags($search_q);

$itog = mysqli_fetch_assoc($q);

The best way to get rid of the bad guy on the site is to let him know those who are wrong. If you are working for a handy system, then your site will be able to increase the speed and speed of your site in order to know those who need to chirp.

I will show you how to create a simple, yet effective for the functionality of the search form, how to use it for search articles on the site. The results will be announced on the side without any re-advancement, which, without a doubt, is the best way to submit information.

I will create 2 files: search.php, which will contain HTML and JavaScript. Another do_search.php file will replace the PHP code. Let's get down to the creation of the first file:

PHP, jQuery search demo

Try to enter the word ajax


Results for

We created a custom HTML form for this file, so we send a POST request to the back end - the do_search.php file.

select_list($sql); if(count($row)) ( $end_result = ""; foreach($row as $r) ( $result = $r["title"]; $bold = " " . $word . "$end_result .= "

  • " .str_ireplace($word, $bold, $result) . "
  • "; ) echo $end_result; ) else ( echo "
  • Nothing was found behind your request
  • "; } } ?>

    PHP-code to write comments, for which you can easily understand the robot of the script. As if there were a lot of data, you will show them to your coristuvachev, seeing those words in bold, like shukav coristuvach.

    Nadamo tsomu trohi CSS:

    Body( font-family:Arial, Helvetica, sans-serif; ) *( margin:0;padding:0; ) #container ( margin: 0 auto; width: 600px; ) a ( color:#DF3D82; text-decoration: none ) a:hover ( color:#DF3D82; text-decoration:underline; ) ul.update ( list-style:none;font-size:1.1em; margin-top:10px ) ul.update li( height:30px; border-bottom: #dedede solid 1px; text-align: left; top:20px; text-align:left; ) #searchresults ( text-align:left; margin-top:20px; display:none; font-family:Arial , Helvetica, sans-serif; font-size:16px; color: #000; ) .word ( font-weight:bold; color:#000000; ) #search_box ( padding:4px; border:solidari 1px #666666; border- radius: 6px;-webkit-border-radius: 6px; ) .search_button ( border:#000000 solid 1px; padding: 6px; color:#000; font-weight:bold; font-size:16px; radius: 6px;-webkit-border-radius: 6px; ) .found ( font-weight: bold ; font-style: italic; color: #ff0000; ) h2 ( margin-right: 70px; )

    The vee axis has learned to create the simplest random form, as it works without re-arranging the side. I spodіvayus, the lesson is worthy of you.

    The article has a report about the replacement of PHP _SELF.

    What is the PHP _SELF change?

    Change PHP _SELF to turn it on and off to the stream file (like the document root). You can twist the change in the attributes of the action form. Learn the same nuances, as you can know. We, obviously, can’t overlook these nuances.

    Let's take a look at the sprat of applications.

    echo $_SERVER["PHP_SELF"];

    1) Acceptable, what is your php file distributions for the next address:

    http://www.yourserver.com/form-action.php

    In my case, change PHP _SELF mіstitime:

    "/form-action.php"

    2) Let's say your php file of orders for this address:

    http://www.yourserver.com/dir1/form-action.php

    PHP _SELF will be:

    "/dir1/form-action.php"

    PHP _SELF in action form attribute. What did you need there?

    chime in Change PHP _SELF tag in the action attribute of the form tag. The action attribute contains addresses, for which a different form will be sent after confirmation (click on the type="submit" button). As a rule, this is the side itself, from which the form was written.

    However, if you rename the file to whatever form is being used for, you will have to rename the file's name in the action attribute, otherwise the form is not valid.

    Changing PHP _SELF will allow you to correct it, so that the side addresses will be generated automatically, depending on the name of the file.

    Let's say you have a file with the form-action.php form, and you want the form to be sent to that file after confirmation. Start writing like this:

    Alternatively, you can change the PHP _SELF over form-action.php. For this vipadka, the code is visible:

    " >

    Code for form-action.php

    Combine the script with the form:

    $name";echo"
    You can win the form to enter a new name."; ) ?> ">

    The code at the top of the HTML page will be marked first. At the first row, the code is revised: the form is given chi nі. If you use $_POST["submit"] , the IF construct will be accepted (TRUE) and will be displayed by the user who entered it.

    If changing $_POST["submit"] is not necessary, the form has not been submitted and, obviously, the IF construct will not be submitted (FALSE). That im'ya koristuvach will not be seen.

    Nebazhanі moments, pov'yazanі zі zminnoyu PHP _SELF

    Changing PHP _SELF to hack in order to take it from there to the stream file - okay, but it can also be hacked by hackers - bad. If you have PHP _SELF on your side, you can enter a forward slash (/) and write XXS scripts.

    Let's look at the example:

    "method="post">

    Now, if you're looking for a home page from a normal URL, then in the address bar it will be on xtalt:
    http://www.yourdomain.com/form-action.php
    and the code, with more guidance, can be read like this:

    In this vipadka, like vie bachite, everything is good.

    Now let's take a look at the situation, if the koristuvach starts "chemistry" with the address row:
    http://www.yourdomain.com/form-action.php/%22%3E%3Cscript%3Ealert("xss")%3C
    /script%3E%3Cfoo%22

    What do you think, if PHP works, your code will look like this:

    You can check for yourself that the code is added to the script tag and the alert command. If this side is zavantazhen, koristuvach slap vikno іz in advance. Here is a simple example of how you can exploit the PHP _SELF change.

    Any JavaScript code can be added between script tags. A hacker can also ask for a JavaScript file that will be passed on to another server. This file, ymovirno, will have a shkidlivy code, for the help of which a hacker can change the global change and forward the form to another address with the method of recopying the data entered by the coristuvach.

    How to get rid of inaccuracies associated with PHP _SELF

    Invalidities can be eliminated by using the htmlentities() function. Take a look at the form code, where is the htmlentities() function.

    "method="post">

    The htmlentities() function converts all possible characters in a valid HTML entity. Now try to bypass the change PHP _SELF will recognize the crash and the result of passing the sloppy code to the offensive one:

    ", and in the password field the text"

    password

    ":

    Once the html code has been overpowered, the JavaScript code will be put in, which will display prompts.

    To get rid of such problems from security, stop the htmlentities() function:

    If(isset($_POST["login"]) && isset($_POST["password"]))( $login=htmlentities($_POST["login"]); $password = htmlentities($_POST["password" ]), echo "Your login: $login
    Your password: $password"; )

    І type after entering the html code or javascript, then the tags will be screened, and we will remove the onset of the flash:

    Another function, the strip_tags() function, allows you to turn off html tags again:

    If(isset($_POST["login"]) && isset($_POST["password"]))( $login=strip_tags($_POST["login"]); $password = strip_tags($_POST["password" ]), echo "Your login: $login
    Your password: $password"; )

    The result of її work, with the introduction of the same, will be the advance of the visnovi.

    © 2022 androidas.ru - All about Android