0

I have 2 php page. I want to redirect page 1 (contains a data (ex. username)) to page 2 that only receive post data.

Here is received code in page 2 (not editable due to development):

if (!$_POST["username"]||$_POST["username"]=="Studio") $username="Studio".rand(100,999);
else $username=$_POST["username"]; 

I tried to use curl for my case, and not get the data I needed.

Here'e my code in page 1:

$src = "http://test.com/test.php"
//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$src);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,"username=".$title);

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);

$this->_redirectUrl($src);
2
  • in order for $username=$_POST["username"]; to work, you need to click SUBMIT button that places the username into the httprequest object. If you can't add it there, you can use cookies and store that data in cookies. Commented Jan 30, 2013 at 3:06
  • @Andrew I can't edit the page 2. so, data must send via post. Commented Jan 30, 2013 at 3:43

1 Answer 1

2

Have you tried using CURL with POST ?

$ch = curl_init();

curl_setopt($ch,CURLOPT_URL, $url); //set URL
curl_setopt($ch,CURLOPT_POST, 1); // make a POST request
curl_setopt($ch,CURLOPT_POSTFIELDS, $post_vars);

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);

$post_vars can be something like 'lastname=smith&firstname=bill'

Sign up to request clarification or add additional context in comments.

3 Comments

Yes, I did. after write that code, then I redirect to page 2. No post variable i found.
How did you redirect? Usually if your'e doing a header redirect, you create a new request, thus loosing the POST
by $this->_redirectUrl($src); (in magento, its used to redirect to external url)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.