Sending $_POST['field'] via browser window and PHP?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Sending $_POST['field'] via browser window and PHP?

Post by Mr Tech »

Hey there,

I want to be able to open a PHP page in a browser window which then redirects to another website but also sending a $_POST['field'] without the use of a form.

Any ideas on how I can do this? I've seen it done with ASP.

Thanks

Ben
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post by protokol »

Put it into the query string. Treat it like a $_GET
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Post by Mr Tech »

But I want it to be hidden.... is it possible?
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post by protokol »

See this post: viewtopic.php?t=28161
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post by xisle »

you can use a hidden input variable, and a form with no button
use JS to open a new window and target the results of the post

Code: Select all

//JS code    
window.open('','results','toolbar=0,width=50,height=50');
document.formї0].target = 'results';
document.formї0].submit();
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Post by Mr Tech »

I don't think i want to use JS:

viewtopic.php?t=28161
viewtopic.php?t=7063

I don't think they are what I need. I don't want to just send a post value but I also want to redirect them page to the page I am sending the post value too.

The reason why I want this is becuase when they login to their script, it then sends them to my website checking their license key.

If the license is valid, it redirects back to the referring website, sending a POST. Once they get back to their script, the script will set a session() with that POST, enabling them, to use the script.

If its not valid, it will send another POST saying that it's not valid.

I suppose this is the sort of thing I would need but I don't know how to get it working:

Code: Select all

<?php
header("POST /index.html HTTP/1.1"); 
header("Host: http://www.algirdas.com"); 
header("User-Agent: Mozilla/4.0"); 
header("Content-Length: 23"); 
header("Content-Type: application/x-www-form-urlencoded"); 
print("merchant_account_id=223");
?>
Thanks for the help!
User avatar
mchaggis
Forum Contributor
Posts: 150
Joined: Mon Mar 24, 2003 10:31 am
Location: UK

Post by mchaggis »

Here is another idea for you...

You could use curl or one of the other file opening functions, that allow you to open urls from within a php, thus no need for you to redirect them, which would also mean that you could do away with the need to post.

Code: Select all

<?
if (!eregi('License Valid',file_get_contents("http://www.algirdas.com/?merchant_account_id=223"))) {
        # License is invalid... do something
        Header("Location: Invalid.html");
}
?>
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Post by Mr Tech »

Thanks mchaggis,

That is a good idea, however, some hosts block that from happening....

Any thoughts?

Cheers,
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Post by Mr Tech »

I gave you code a whirl anyway and am getting this error:


Parse error: parse error, unexpected $ in c:\program files\easyphp\www\created\post\check.php on line 7


Heres the code:

Code: Select all

<?
if (!eregi('License Valid',file_get_contents("test.php?valid=no"))) {        
echo "valid";
} else {
echo "not valid";
?>
?>
Wots wrong with that?
Bennettman
Forum Contributor
Posts: 130
Joined: Sat Jun 15, 2002 3:58 pm

Post by Bennettman »

Missing end bracket at the end. You don't need any brackets if you've only got one command to run in an if/else anyway.
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Post by Mr Tech »

LOL how did I miss that... Seems to work fine now thanks ;)
Post Reply