sd9sd Posted June 30, 2008 Share Posted June 30, 2008 Hi, I'm trying to execute a PHP file from another PHP file. I've tried writing my own code (below) but it didn't work. Also tried using the exec command, but couldn't get it to work. Could I have some guidance of how to make it work/ Sender PHP (the 'done sending message' also has to work) <?php $hello="yo"; echo "sending message<br>"; echo "receiverPHP.php?hi=$hello"; echo "done sending message<br>"; ?> Receiver PHP <?php $mssg = $_POST['hi']; echo "The message is $mssg<br>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/112534-solved-executing-another-php-from-a-php/ Share on other sites More sharing options...
interpim Posted June 30, 2008 Share Posted June 30, 2008 You could include it where you want it. <?php $hello="yo"; echo "sending message<br>"; include(receiverPHP.php?hi=$hello); echo "done sending message<br>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/112534-solved-executing-another-php-from-a-php/#findComment-577841 Share on other sites More sharing options...
MasterACE14 Posted June 30, 2008 Share Posted June 30, 2008 you have $_POST['hi']; are you trying to send data from 1 php file to the other so the second php file can run some tasks with the POST ? Quote Link to comment https://forums.phpfreaks.com/topic/112534-solved-executing-another-php-from-a-php/#findComment-577849 Share on other sites More sharing options...
sd9sd Posted June 30, 2008 Author Share Posted June 30, 2008 Thanks interpim...but it doesn't work. The receiver file doesn't print out the hello word. you have $_POST['hi']; are you trying to send data from 1 php file to the other so the second php file can run some tasks with the POST ? Yes. Quote Link to comment https://forums.phpfreaks.com/topic/112534-solved-executing-another-php-from-a-php/#findComment-577868 Share on other sites More sharing options...
MasterACE14 Posted June 30, 2008 Share Posted June 30, 2008 change $mssg = $_POST['hi']; to $mssg = $_GET['hi']; as your sending the data via the URL, it is actually a GET not a POST. Quote Link to comment https://forums.phpfreaks.com/topic/112534-solved-executing-another-php-from-a-php/#findComment-577875 Share on other sites More sharing options...
sd9sd Posted June 30, 2008 Author Share Posted June 30, 2008 Thanks masterace14! it works. I was under the impression that a post is used whenever you don't want the query string to show up in the address bar. Guess it isn't that way after all Quote Link to comment https://forums.phpfreaks.com/topic/112534-solved-executing-another-php-from-a-php/#findComment-577882 Share on other sites More sharing options...
MasterACE14 Posted June 30, 2008 Share Posted June 30, 2008 no problem. POST is used for forms. example: <form method="post" action="blah.php"> <input type="text" name="text"> <input type="submit" value="submit"> </form> then in blah.php you can have this: <?php if(isset($_POST['text'])) { echo $_POST['text']; } ?> GET can be used in forms and in the URL. Example: <a href="www.somewebsite.com/page.php?text=text">submit some text</a> page.php: <?php if(isset($_GET['text'])) { echo $_GET['text']; } ?> Also POST is used when you have a large amount of data to send to another page. GET is also used for things such as 'news' on your website or whatever so people are able to bookmark the page(bookmarking the exact news article by the GET in the URL). Regards ACE Quote Link to comment https://forums.phpfreaks.com/topic/112534-solved-executing-another-php-from-a-php/#findComment-577885 Share on other sites More sharing options...
sd9sd Posted June 30, 2008 Author Share Posted June 30, 2008 thanks Quote Link to comment https://forums.phpfreaks.com/topic/112534-solved-executing-another-php-from-a-php/#findComment-577963 Share on other sites More sharing options...
MasterACE14 Posted June 30, 2008 Share Posted June 30, 2008 no problem Quote Link to comment https://forums.phpfreaks.com/topic/112534-solved-executing-another-php-from-a-php/#findComment-577971 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.