Posting variable to a script without submitting via form?
01-03-2008, 09:08 PM
|
Posting variable to a script without submitting via form?
|
Posts: 6,521
Name: Dan
Location: Swindon
|
okay this may sound weird but im clueless on hwo to do it.
how can i post something to a script without actually submitting it with a form
so i need to know how to write a script which could post
$varablea and $varableb to a script as if it has been submitted through a form where the names was var1 and var2
does anyone get what i mean and can provide a answer?
__________________
Discounted Web Hosting With XDnet! >> Get 25% of hosting~ Promo: Webmaster-talk <<
|
|
|
|
01-04-2008, 04:33 AM
|
Re: Posting variable to a script without submitting via form?
|
Posts: 88
Name: programmer
Location: internet
|
huh?
Assuming that echo $varablea would not suffice your needs. You must have some other stuff going on.
My question is do you need the variables to post when the page loads or because of some certain condition which will happen within the script. ie maybe based on the time it would post etc..
Without more info it would be hard to tell you. But it sounds like ajax may help. Using php and ajax you could submit the variables/ post them behind the scenes with ajax without actually refreshing the page (I'm also assuming you do not want the page to refresh or you could just submit the variables $_GET like).
I'm sure I could help more if you were a little more specific with what you want to do.
|
|
|
|
01-04-2008, 05:34 AM
|
Re: Posting variable to a script without submitting via form?
|
Posts: 219
Name: Rob
Location: UK
|
Most reliable method is using a hidden form. The form would have hidden fields and this could be submitted with a link using js onclick or any other event handler.
Code:
<a href="#" onclick="document.form1.submit();">Post variables</a>
Other alternative is to using phps cURL function http://uk.php.net/curl
PHP Code:
<?php $URL="www.mysite.com/script.php"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"https://$URL"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, "var1=blah&var2=blah");curl_exec ($ch); curl_close ($ch); ?>
Last edited by maxxximus; 01-04-2008 at 06:09 AM..
|
|
|
|
01-04-2008, 09:32 AM
|
Re: Posting variable to a script without submitting via form?
|
Posts: 6,521
Name: Dan
Location: Swindon
|
okay sorry im not sure here.
basically it will be used as a (non malicious) bot like script.
so would that curl work?
so all would need to do is change the var thing and the would be the equiv of what name="" would equal in a form?
and then after this could i have it header(location) to url so i could go on a page and have it login or something and redirect to the login page without entering any info?
__________________
Discounted Web Hosting With XDnet! >> Get 25% of hosting~ Promo: Webmaster-talk <<
|
|
|
|
01-04-2008, 07:59 PM
|
Re: Posting variable to a script without submitting via form?
|
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
|
If I understand you right, you should just be able to post using the URL parameters ($_GET) vars
__________________
<mgraphic /> - I don't have a solution but I admire the problem.
|
|
|
|
01-05-2008, 08:35 AM
|
Re: Posting variable to a script without submitting via form?
|
Posts: 6,521
Name: Dan
Location: Swindon
|
Not if the script i wish to post to doesnt support that
i should say in some cases i wont be able to edit the script im posting to so it does need to be with the POST method
That curl didnt seem to work but im not sure if i was using it right 
__________________
Discounted Web Hosting With XDnet! >> Get 25% of hosting~ Promo: Webmaster-talk <<
|
|
|
|
01-05-2008, 09:31 AM
|
Re: Posting variable to a script without submitting via form?
|
Posts: 219
Name: Rob
Location: UK
|
Dan - why dont you give us an idea what your trying to do.
Post your script and we'll try and help you out.
|
|
|
|
01-05-2008, 11:14 AM
|
Re: Posting variable to a script without submitting via form?
|
Posts: 6,521
Name: Dan
Location: Swindon
|
well it needs to be general really, it is the script if you get what i mean i have many ideas of what i can use it for, one being a logger in for my personal use so i can have a script which enters my usernames and passwords to multiple sites and/or opens that site so when i go to it im already logged in.
also im thinking of using it for testing purposes on register forms etc as well as a few others.
Sorry i know i am being vague.
@maxxximus
can you explain more on how i could use this?
Quote:
PHP Code:
<?php $URL="www.mysite.com/script.php"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"https://$URL"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, "var1=blah&var2=blah");curl_exec ($ch); curl_close ($ch); ?>
</SPAN>
|
__________________
Discounted Web Hosting With XDnet! >> Get 25% of hosting~ Promo: Webmaster-talk <<
|
|
|
|
01-05-2008, 11:21 AM
|
Re: Posting variable to a script without submitting via form?
|
Posts: 6,521
Name: Dan
Location: Swindon
|
just seen php/curl
and found this post which im guesisng is where u got the code from Maxxximus?
Quote:
There is a problem with uploading files via CURL. However the issues regarding the @ symbol as well as references to url_encoding are not the cause of the bug.
The @ symbol is used to send the contents of a file, rather than the string representation of the file path, to the receiving script. (See Below)
In other posts on this site references are made to CURLOPT_POSTFILEDS being populated with an array of post variables, however the documentation is clear, this variable is supposed to be a string,....therefore the following should work.
function Post($vars,$url){
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,1);
#curl_setopt($ch,CURLOPT_UPLOAD,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$vars);
curl_exec($ch);
curl_close($ch);
}
$path = "/tmp/test.txt";
$url = "http://www.somesite.com/receive_changes.php";
$vars = "action=submitted&order=receive&file=@$path";
Post($vars,$url);
Unfortunately this does not work.
|
__________________
Discounted Web Hosting With XDnet! >> Get 25% of hosting~ Promo: Webmaster-talk <<
|
|
|
|
01-05-2008, 11:29 AM
|
Re: Posting variable to a script without submitting via form?
|
Posts: 6,521
Name: Dan
Location: Swindon
|
oo i just had a idea.
on the test one (calmcharity login) it has two forms and its the second (the login not the search) i want it submitted to, is it just submitting to like the first form?
__________________
Discounted Web Hosting With XDnet! >> Get 25% of hosting~ Promo: Webmaster-talk <<
|
|
|
|
01-05-2008, 11:40 AM
|
Re: Posting variable to a script without submitting via form?
|
Posts: 219
Name: Rob
Location: UK
|
The script will use the POST method to send the variables var1 and var2 to https://www.mysite.com/script.php using the cURL client.
You would then retrieve the values in script.php just as if they had been posted with a form
$foo = $_POST['var1'];// "blah"
The only thing that the script above does not include is an echo of the curl_exec.(included below)
PHP Code:
<?php
$URL="http://www.mysite.com/script.php"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"$URL"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, "var1=blah&var2=blah"); $out=curl_exec ($ch); echo $out; curl_close ($ch); ?>
This is equivalent to
HTML Code:
<form action="http://www.mysite.com/script.php" method="post">
<input name="var1" type="text" id="var1" value="blah" />
<input name="var2" type="text" id="var2" value="blah" />
<input name="" type="button" /></form>
</form>
Edited to add that there's a good tool for Firefox https://addons.mozilla.org/en-US/firefox/addon/3829 to view live headers.
Last edited by maxxximus; 01-05-2008 at 11:49 AM..
|
|
|
|
01-05-2008, 11:51 AM
|
Re: Posting variable to a script without submitting via form?
|
Posts: 6,521
Name: Dan
Location: Swindon
|
okay, so does this mean that this:
PHP Code:
<?php $URL="uk.calmcharity.org/login.php?action=login&redirect=/admin/"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"http://$URL"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, "user=admin&password=*******&submit="); curl_exec($ch); curl_close($ch); ?>
should log into the site?
__________________
Discounted Web Hosting With XDnet! >> Get 25% of hosting~ Promo: Webmaster-talk <<
|
|
|
|
01-05-2008, 11:53 AM
|
Re: Posting variable to a script without submitting via form?
|
Posts: 6,521
Name: Dan
Location: Swindon
|
i have this script and it seems to post but it dont log in, the navigation shows the buttons for a logged in user but it dont seem to have set the session?
so when click links it reuses also admin show sin the username field on the login...
it should redirect to /admin/ on login..
__________________
Discounted Web Hosting With XDnet! >> Get 25% of hosting~ Promo: Webmaster-talk <<
|
|
|
|
|
« Reply to Posting variable to a script without submitting via form?
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|