Jump to content

how to post parameters and redirect to another url using PHP

- - - - -

  • Please log in to reply
1 reply to this topic

#1
lol33d

lol33d

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
hi guys

i need to post parameters and redirect to another url using PHP

this is my code using HTML, i need using php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">


	<html>

	<head>

	<title></title>

	<script language=javascript>

	function submitform()

	{

	document.goPostBack.submit();

	}

	</script>

	</head>

	<body onload="submitform()">

			<form action="http://www.url.com/?p=we" method="POST" name="goPostBack" id="goPostBack">

			<input type="hidden" name="COCK" value="OKAY">

			<input type="hidden" name="price" value="900000">

	</form>

this code auto submit and send parameters and go to url

i need using php

#2
SoN9ne

SoN9ne

    Programmer

  • Members
  • PipPipPipPip
  • 129 posts
What exactly are you trying to do?

If you just need to post parameters then you only need to create a simple HTML form and have it post to the PHP file.
The PHP file can then process the POST parameter and then forward to a new URL or URI if applicable.

<form method="post" action="/someFile.php">

<fieldset>

    <label for="qq-30">Label</label>

        <input type="text" id="qq-30" name="qq-30" value="" />

</fieldset>

<fieldset>

    <input type="hidden" value="3e18aa789cc3dae98656dad64857214e57fad630" name="csrf">

    <input type="submit" value="Submit">

    <input type="reset" title="Reset the form?" value="Reset">

</fieldset>

</form>

<?php 

// Define valid post data

$validPostData = array();


// Set valid post data

$validPostData['question_30'] = isset($_POST['qq-30']) ? sanitizeString($_POST['qq-30']) : NULL;


// Do whatever with your valid post data here


// redirect to external site:

header('Location: http://newsite.com');

// or you can do this for local redirects

header('Location: /localFile.php');


/**

 * Sanitizes the string

 * - All strings are forced to UTF-8 encoding

 * @param string $string

 */

function sanitizeString($string) {

	return htmlentities( (string) $string, ENT_COMPAT, "UTF-8" );

}

?>

This is a very simple and bland way of handeling form data.
You need to first identify how you want to handle the form data/submission.
The redirect is easy to apply (just remember that no output can be sent to the user else the header() method will fail).

Let me know if this helps and try to clarify what you are trying to accomplish. :)

Note: you will see I have a hidden field called csrf... this is from my form system to prevent cross-site requests forgery... you may want to look into this as it is really easy to prevent and is a big problem for most web forms.

Edited by SoN9ne, 16 November 2011 - 12:09 PM.

"Life would be so much easier if we only had the source code."




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users