change button action to url address or bash script - php

There is a button in a site like this:
<form method="POST" action = "/invite/1233">
<input type="hidden" name="t" value="4b16d">
<button type="submit">submit</button>
</form>
How can I "emulate" pressing this button for example in bash? Is it possible to make an adress that I can click instead of this button? Why http://site-domain-here/invite/1233?t=4b16d doesnt work?

On your terminal, assuming you have curl installed (who doesn't?), run:
curl -d "t=4b16d" http://site-domain-here/invite/1233
The -d option means that the request will be made with POST.
In response to your addition to your question:
Why http://site-domain-here/invite/1233?t=4b16d doesnt work?
This is because by following the link above you are by default issuing a GET request; not a POST request with post data which is what the web page/service requires.
See http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods for an explanation of the various HTTP request "verbs".

Related

How to get page body after POST request

I'm trying to make a PHP page that lets you upload a document to telegram servers and than retrives a file_id which is stored in the json of the redirect page. After some tutorials on YT this is the code:
<?php
$botToken = "1099xxxxxx:AxxxE-g9qDI2Uxxxxxxxxxxxxxxxxxxxxxxxx";
$website = "https://api.telegram.org/bot".$botToken;
?>
<form action="<?php echo $website.'/sendPhoto' ?>" method="post" enctype="multipart/form-data">
<input type="text" name="chat_id" value="mychatid">
<input type="file" name="photo">
<input type="submit" value="send">
</form>
Redirect after submit
The goal is to retrive the file_id of the file and save it in a variable, possibly without opening another tab.
Thanks!
You've making the request to the Telegram API from the browser by submitting a form directly to it.
There is no way your PHP can get any information from that API that way.
As a side effect, you are giving your token (which should be kept secret) to every visitor who uses the form.
You need the browser to submit the form to a PHP program you control and then make the request to the Telegram API from your PHP and not from the browser.
The usual way to do this is with the cURL library.

Link click and button click in one HTTP request

I was developing on my localhost and came across this question.
Consider there is such HTML code:
<form action="" method="POST">
<input type="submit" name="submitButton" id="submitButton">
</form>
<a onclick="clickButton('submitButton');" href="guestbook/index.php?pageNumber=1">
The <a> click triggers submit button click event. The Javascript function looks like this:
function clicktButton(id) {
if (id != "")
document.getElementById(id).click(); // this will trigger the click event
}
My question is: is something like this possible? To send a HTTP request with link press and button press simultaniously?
Because by pressing an <a> link I already send a HTTP request with $_GET['pageNumber'] parameter. But I also want to send the $_POST['submitButton'] data at the same time.
Thanks in advance!
What you want is possible, but not so much with the code I see before me..
<form action="guestbook/index.php?pageNumber=1" method="post">
<input type="submit" name="submitButton" id="submitButton">
<input type="button" name="submit">
</form>
This would essentially post the contents of the form, with a get request attached.
An <a> would not really work, because it generates a new HTTP request and would presumably skip JavaScript execution of the currently loaded page.
On the other hand, you can simulate the effects of an <a> click with JavaScript, by making a post request with the form data to guestbook/index.php?pageNumber=1. But if you do this I would recommend jQuery as it will make things easier for you by adding this to the click event.
$.ajax({
url: "guestbook/index.php?pageNumber=1",
data: {'field':'value'},
async: false
});

PHP that accepts file upload from a single HTTP POST

I'm trying to figure out how to get a server to accept a file through HTTP post in one step - without going through all the trouble of creating an html form and clicking the submit button.
I know how to write a PHP/HTML package that accomplishes the following:
user points their local browser to a URL with an upload form
user selects a local file and clicks "upload" button on the form
server accepts that file and places it in a specified place
I create an HTML file with a form that calls a php script when the submit button is clicked.
I'd like to change this to the following:
From command line, user executes the following command:
"curl -X POST #somefile http://myhost/getter.php"
server (myhost) accepts that file and places it in a specified place
Said another way, I'd like to send the file directly to the php script without going through the form step.
Much thanks for any guidance.
http://curl.haxx.se/docs/httpscripting.html
4.3 File Upload POST
<form method="POST" enctype='multipart/form-data' action="upload.cgi">
<input type=file name=upload>
<input type=submit name=press value="OK">
</form>
command line equivalent:
curl --form upload=#localfilename --form press=OK [URL]

PHP cURL post to a form that is being processed by jQuery?

Ok, so usually I would lookup the form's action attribute (ex: request.php) and would do a cURL post request to that page, but what if the form is being processed by jQuery?
Example
<form method="post" action="profile/post/USERNAME" id="postForm"
onsubmit="funct.post('USERNAME'); return false;" >
...
<input type="button" class="sendButton" id="sendBtn" value="Send"
onclick="funct.post('USERNAME')" />
I have no idea how to work with this form, I've tried submitting to the /profile/post/USERNAME page, but that doesn't work.
Am I missing something?
Actually, I was having problems because the form is using AJAX to post the form.
If looking through MASSIVE, unformatted amount of jQuery code (like in my case) is a problem and doesn't lead anywhere, then a good idea is to look at the headers that are being sent to the server.
I used HTTP Live Headers addon for Firefox to see just that, and noticed that the actual query was token=4324234324&note=My+Note&ajax=1
Both token and note were present in the form, token as hidden and note as text input, but the ajax=1 is inserted somewhere when it's processed by jQuery.
Headers Don't Lie!

open url from button using php

I need to make a button that:
Send to php script variable pressed=true when its pressed
open new tab with an adress
How can I do it without using java-script?
PHP can't cause events to happen in the client browser, you will need javascript for that. The button would have to submit the data to the PHP script, and then the script would display whatever output you like.
You could do this however
<FORM ACTION="phpscript.php" METHOD="POST" TARGET="_BLANK">
<BUTTON TYPE="submit" VALUE="1" name="pressed">Click</BUTTON>
</FORM>
This will open a new window(tab in FireFox at least)and you will have passed the value to your PHP script.
In your PHP script you check the value, and use a header to specify a new address:
if($_POST['pressed'] == 1 )
header("Location: http://www.whatever.com");

Categories