1


I want to post a value of a variable from one php file(1.php) to another file(3.php) by php(not using ajax) without using form. how can I do that ?
suppose, in '1.php' "$a=10;" I would like to post this value to '3.php' without using any form and I want nobody could see that value on browser's address bar.(Note: If anybody suggest me to use 'httprequest' then please write a simple code in php to do that.I can do that by using ajax but can't by php.And please tell me how do you send a seller's paypal account id to paypal for processing payment as it needs to be secured.)
I got some code but its not working, don't know whats wrong.

1.php

<?php
$data = array(); $data['first_name'] = 'hello'; $data['last_name'] = 'Thind'; $data['password'] = 'secret'; $data['email'] = 'me@abc.com';
$post_str =''; foreach($data as $key=>$val) { $post_str .= $key.'='.urlencode($val).'&'; } $post_str = substr($post_str, 0, -1);
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, '3.php' );
curl_setopt($ch, CURLOPT_POST, TRUE); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_str);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $result = curl_exec($ch); curl_close($ch); echo $result;
?>   


3.php

<?php
$host="localhost";       
$dbname="mr"; 
// mysql code for table= create table m(name varchar(10));
$username="";            
$password="";
$con=mysql_connect("$host","$username","$password")or die("cannot connect");
mysql_select_db($dbname) or DIE('cannot select db');
if(isset($_POST['first_name'])){
$name=$_POST['first_name'];
$sql="insert into m
values($name)";
$sq=mysql_query($sql);  
}
mysql_close($con);
?>


[Note: please tell me without using SESSION or 'data from external file'] Can anybody please help me ?

-Thanks.

user1826381
  • 43
  • 1
  • 2
  • 7

2 Answers2

1

You can set the value in the session in the first PHP and then when the second PHP page loads, you can read it from the session back.

Sudar
  • 18,954
  • 30
  • 85
  • 131
0

Using

file_get_contents()

function you can do this Here is the one article regarding this http://phptechworld.blogspot.in/2012/09/how-to-call-external-url-and-print.html

vvr02
  • 611
  • 2
  • 12
  • 22