Current location: Hot Scripts Forums » Programming Languages » PHP » Help with php value passing


Help with php value passing

Reply
  #1 (permalink)  
Old 03-28-06, 08:59 PM
david510 david510 is offline
Newbie Coder
 
Join Date: Mar 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Help with php value passing

Hi all,

Can anyone find a solution for me.

I need to get the value that is diplayed when I take www.domain1.com/test.php and pass it to www.domain2/test.php. For example www.domain1.com/test.php contains this code <? echo "hello" ?>. Now when we take www.domain1.com/test.php in browser hello is displayed. I need hello to be passed to www.domain2.com/test.php , when www.domain2.com/test.php is taken in browser.

Please help me

David

Last edited by david510; 03-28-06 at 09:02 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 03-28-06, 10:07 PM
Crassius Crassius is offline
Newbie Coder
 
Join Date: Mar 2006
Location: Melbourne, FL
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
in domain2.com/test.php add this code.

PHP Code:

<?php

include("www.domain1.com/test.php");
?>
__________________
~With great power comes great responsibility.~

Last edited by Christian; 03-29-06 at 12:28 AM. Reason: Please use [PHP][/PHP] when posting php code
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 03-29-06, 01:19 AM
david510 david510 is offline
Newbie Coder
 
Join Date: Mar 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Hey Crassius,

Thank you so much. I am going to love this forum a lot!!


David
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 03-30-06, 07:25 PM
david510 david510 is offline
Newbie Coder
 
Join Date: Mar 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
I got the following worked.
PHP Code:

<?php

include("www.domain1.com/test.php");
?>
How can I pass the value returned by include("www.domain1.com/test.php"); into a variable say, $var1 ?

Last edited by Christian; 03-31-06 at 08:04 PM. Reason: Please use [PHP][/PHP] when posting php code
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 03-31-06, 09:14 AM
nova912's Avatar
nova912 nova912 is offline
Code Guru
 
Join Date: Sep 2004
Location: Traverse City, MI, USA
Posts: 821
Thanks: 0
Thanked 0 Times in 0 Posts
Well if you include(); then all the php from that page is just in essence pasted onto the current page and the variable is still active untill the script is over.

So you should be able to just use that var in this current script.

like say:

PHP Code:

$var $included_var 

(see how included var is already set)

Best answer I can give =/ sorry hope it helps a bit.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 03-31-06, 11:12 AM
david510 david510 is offline
Newbie Coder
 
Join Date: Mar 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks for the reply!

I used like this, but it is not working.

PHP Code:

<?

$var 
= include("http://domain.com/test.php");
echo 
$var;
print 
$var;
?>
This script is not printing the value of $var

Last edited by Christian; 03-31-06 at 08:05 PM. Reason: Please use [PHP][/PHP] when posting php code
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 03-31-06, 01:26 PM
gorivo's Avatar
gorivo gorivo is offline
Newbie Coder
 
Join Date: Mar 2006
Location: Lithuania
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
if you only need to take the output of file, use this:

PHP Code:

<?php


ob_start
();

include 
"somefile.php";

$var1 ob_get_contents();
ob_end_clean();

?>
OR simply :

PHP Code:

<?php


$var1 
file_get_contents('somefile.php');

?>
Hope this will help!
Gorivo.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 03-31-06, 01:30 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
When you include a file from a remote system it is parsed on that system 1st. Therefore, you only "see" any output from that file. Hence, in your example - echo "hello"; in the remote file gives you hello as the result.

You can get the contents of a remote web page/file into a variable, using the file_get_contents() function - http://us2.php.net/manual/en/functio...t-contents.php If this is more than just the output from an echo (ie. a whole web page) you will need to search/parse the resultant string to find what you are expecting to get.

I seriously recommend downloading a copy of the PHP manual for reference. I personally use the chm version. In the above case, on the page for include, the "also see" section at the bottom shows the readfile() function. Readfile reads into the output buffer, but in the "also see" section of this page is file_get_contents, which reads into a string.

Also, browsing and/or searching (the search in the chm version works well) through the php manual will help make you more familiar with the functions available, so you will be able to find basic solutions on your own.

Download the php manual here - http://us2.php.net/download-docs.php
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 03-31-06, 08:03 PM
david510 david510 is offline
Newbie Coder
 
Join Date: Mar 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Awesome!!

I was able to get the value in a variable

with the code below and print the vlaue of $var1

PHP Code:

ob_start();


include 
"somefile.php";

$var1 ob_get_contents();
ob_end_clean(); 
Now I need to passthis value into the html code within the same file. Say, I am including two files like this somefile.php (var1) and someotherfile.php (var2) into this php code. Now when I pass var1 as the bgcolor in the html table color should be Red and when I pass var2 as bgcolor the table color shoufl be Yellow. I enter Red in somefile.php and Yellow in someanotherfile.php.

<table border="1" bgcolor=$var1>
<tr><td>Row 1 Cell 1</td><td>Row 1 Cell 2</td></tr>
<tr><td>Row 2 Cell 1</td><td>Row 2 Cell 2</td></tr>
</table>

I hope I am clear enough.

Last edited by Christian; 03-31-06 at 08:05 PM. Reason: Please use [PHP][/PHP] when posting php code
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 04-01-06, 04:41 AM
gorivo's Avatar
gorivo gorivo is offline
Newbie Coder
 
Join Date: Mar 2006
Location: Lithuania
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
David,

if your somefile.php and someotherfile.php contains only
PHP Code:

<?php echo 'COLOR NAME'?>

you should better user file_get_contents() function not ob_start();

not sure i understood you correctly, but maybe this will help:

PHP Code:

<?php


# $var1 will be set to RED
$var1 file_get_contents('somefile.php');

# $var2 will be set to YELLOW
$var2 file_get_contents('someotherfile.php');

echo 
'<table border="1" bgcolor='.$var1.'>
<tr><td>Row 1 Cell 1</td><td>Row 1 Cell 2</td></tr>
<tr><td>Row 2 Cell 1</td><td>Row 2 Cell 2</td></tr>
</table>'
;

?>
Gorivo.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing Javascript Variable to PHP watadude PHP 4 01-15-11 07:44 PM
PHP multi-dimensional array sorting issue aqw PHP 2 06-25-05 12:09 AM
PHP / Graphic Developers someotherguy582 Job Offers & Assistance 1 06-05-05 08:40 PM
Passing a PHP variable in Javascript??? todayscoffee JavaScript 2 01-08-05 10:45 AM
Passing a PHP variable in Javascript??? todayscoffee PHP 2 01-04-05 02:56 PM


All times are GMT -5. The time now is 10:18 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.