Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 5th, 2008, 01:08 PM
Registered User
 
Join Date: Apr 2008
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default send variables from a PHP script.....

How can I send variables from a PHP script to another URL using POST without using forms and hidden variables???

any idea...????


http://www.hopeandserenity.com/
addiction treatment center.
 
Old June 2nd, 2008, 04:08 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 166
Thanks: 2
Thanked 33 Times in 33 Posts
Default

Use GET! That is, put them in the querystring for the URL (page.php?myvar=foo), and then use $_GET['myvar'] the same as with $_POST.

If the pages are on the same site, you could also put the variables into $_SESSION, but it depends what the variables contain and what you are doing with them.
 
Old June 23rd, 2008, 02:45 PM
Registered User
 
Join Date: Jun 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Maybe this little stream-based solution would do the trick. A stream context is created by passing all necessary params as part of an multidimensional array. Readfile() will output the result of this http-post-request.

Code:
<?php
  $params = array(
              'http' => array(
                'method'     => 'POST',
                'user_agent' => 'Mozilla/5.0',
                'content'    => 'variable=value',
                'header'     => 'Accept-language: en\r\n'.
                                'Cookie: PHPSESSID=54321\r\n'.
                                'Cache-Control: max-age=0\r\n'.
                                'Content-Type: application/x-www-form-urlencoded\r\n'
              )
            );

  $context = stream_context_create($params);
  readfile('http://somehost.com/somescript.php', 0, $context);
?>
Best regards
Jörg





Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing & retrieving variables tto another script topshed Classic ASP Basics 5 October 11th, 2007 05:07 AM
Passing Variables from PHP to PHP brian3166 PHP How-To 4 January 31st, 2005 12:44 AM
The server side script is not send to the browser jaideepc ASP.NET 1.0 and 1.1 Basics 3 February 28th, 2004 12:23 AM
Can I declare variables visable from every script Makis Beginning PHP 1 January 11th, 2004 02:02 AM
Call and run CGI script from a PHP script ... how? dbruins BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 June 10th, 2003 03:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.