Jump to content
xisto Community
hujtec

Php Post Command

Recommended Posts

Hello I've been trying to connect two PHP scripts that have their separate logins. I want to create a PHP script that will use POST to send the username/password to another PHP script. I tried a lot of scripts but I can't seem to make it work. I have no idea how to find out what is wrong, has anybody any experience in this field?

Share this post


Link to post
Share on other sites

What have you tried so far? To move from page to page on a site and maintain data about the user's log-in status (ie: id and password) and various other info, look at using cookies or sessions.

Share this post


Link to post
Share on other sites

Ok, on the origonal page you need to use php to dynamicly write the username and password into a hidden form. It'll look something like this:<form action="nameOfSecondPage.php" method="post"><input type="hidden" name="username" value="<?php $username ?>"><input type="hidden" name="password" value="<?php $password ?>"><input type="submit" value="Goto next page"></form>Then on the second page you just get the variables that you sent, like so:<?php$username=$_POST['username'];$password=$_POST['password'];?>Hope that helped, feel free to ask if you have any other questions

Share this post


Link to post
Share on other sites

Hello I've been trying to connect two PHP scripts that have their separate logins. I want to create a PHP script that will use POST to send the username/password to another PHP script. I tried a lot of scripts but I can't seem to make it work. I have no idea how to find out what is wrong, has anybody any experience in this field?


people often just forget to declare back there variables that are transfered from on page to the other. Make sure that all form varialbles are declared....

eg $name=$_POST['formvariable'];
Edited by bapplay (see edit history)

Share this post


Link to post
Share on other sites

<form action="nameOfSecondPage.php" method="post"><input type="hidden" name="username" value="<?php $username ?>">
<input type="hidden" name="password" value="<?php $password ?>">
<input type="submit" value="Goto next page">
</form>

In the above script, the user has to click the button "Goto next page"

but what if he follows any link?

Share this post


Link to post
Share on other sites

Assuming I understand your problem correctly, you can either specify the script in the 'action' value of the form (eg. '<form action="/target_script.php" method="post">), or include() the script from the page that you have the form submit data to. The $_POST variable is an 'autoglobal', meaning that any section of any script has access to it. So if, for example, you use include('other_script.php'); from within target_script.php, then other_script.php will have full access to the $_POST variable. If that makes sense...

Edited by Spectre (see edit history)

Share this post


Link to post
Share on other sites

I think my question was not clear enough.

You are talking about the usual POST usage.. user clicks a button and the form data is sent.

I was thinking more like automatic posting from PHP (see example )

I tried everything, but the above link now works for me.. I'm really happy about that. :)

Thanks anyway

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.