hackalive Posted April 2, 2010 Share Posted April 2, 2010 Hi guys, I have an index.php page which run some code and executes a few functions which should echo it in a certain location, instead it continues to echo in the top left of the index.php echothis.php (file that should be echoed to certain location) <?php echo $_SESSION['login_to']; ?> <h4>WLWW</h4> function2.php (file calling the function whcih call for insert purposes echothis.php <?php function insertt(){$require_once = $_SERVER['DOCUMENT_ROOT'].'/echothis.php'; require_once($require_once); } ?> function1.php (calls function2.php where needed) <?php function go(){ insertt();?> index.php <H4>WELCOME</H4><?php go(); ?> I have left out the top require require_onces for the files but as you can see index.php require_onces function1.php, function1.php calss function2.php and function2.php echothis.php any help is much appreciated Link to comment https://forums.phpfreaks.com/topic/197334-echoing-in-wrong-place/ Share on other sites More sharing options...
hackalive Posted April 2, 2010 Author Share Posted April 2, 2010 so what is the "correct" way to do this Link to comment https://forums.phpfreaks.com/topic/197334-echoing-in-wrong-place/#findComment-1035787 Share on other sites More sharing options...
monkeytooth Posted April 2, 2010 Share Posted April 2, 2010 I dunno, but to me thats looks like a lot of calling this that and the other for no reason what so ever. Why not instead where ever you want this particular session to display try <?php if(isset($_SESSION['login_to'])){echo $_SESSION['login_to'];}else{echo "some alternative as the session isn't set"} ?> Just a thought, I don't know what your particularly doing, and what other stuff you have in your files other than you showed here.. but sessions are like cookies, and the easiest way I can think to describe them is they float in mid air and you can pluck them down when ever, just like cookies except they store on the server side, not the client side or something like that.. Link to comment https://forums.phpfreaks.com/topic/197334-echoing-in-wrong-place/#findComment-1035789 Share on other sites More sharing options...
hackalive Posted April 2, 2010 Author Share Posted April 2, 2010 monkeytooth thanks for your help but unfortuanately I cannot use your code, so if anyone else has any ideas Link to comment https://forums.phpfreaks.com/topic/197334-echoing-in-wrong-place/#findComment-1035797 Share on other sites More sharing options...
hackalive Posted April 2, 2010 Author Share Posted April 2, 2010 in essence I want to call a PHP file which is like an "app" with tables etc (whatever I write) into my CMS on the relevant page, so if there are any better ways people can suggest Link to comment https://forums.phpfreaks.com/topic/197334-echoing-in-wrong-place/#findComment-1035798 Share on other sites More sharing options...
hackalive Posted April 2, 2010 Author Share Posted April 2, 2010 for some stupid reason it is echoing before it compiles it all together with the other code Link to comment https://forums.phpfreaks.com/topic/197334-echoing-in-wrong-place/#findComment-1035809 Share on other sites More sharing options...
hackalive Posted April 2, 2010 Author Share Posted April 2, 2010 I have no idea how to do this, but I am thinking what if I convert the echothis.php to HTML so not (or maybe I have no idea) have require_once('echothis.php) and have phphtml('echothis.php') and even if this is not a viable solution for this problem I would like to know if such a PHP function exists thanks The require_one is making the content display early so I need another way of calling, that is the problem, or at least part of Link to comment https://forums.phpfreaks.com/topic/197334-echoing-in-wrong-place/#findComment-1035815 Share on other sites More sharing options...
hackalive Posted April 2, 2010 Author Share Posted April 2, 2010 having function.php as return "AAA"; instead of with require_once places the contents in the right spot, so I need to do something other than require_once in order to dsiplay the whole page Link to comment https://forums.phpfreaks.com/topic/197334-echoing-in-wrong-place/#findComment-1035821 Share on other sites More sharing options...
hackalive Posted April 2, 2010 Author Share Posted April 2, 2010 I have done a bit more fiddiling and it is definetly becuase of the require_once so I need a new way of doing this Link to comment https://forums.phpfreaks.com/topic/197334-echoing-in-wrong-place/#findComment-1035835 Share on other sites More sharing options...
hackalive Posted April 2, 2010 Author Share Posted April 2, 2010 someone must have an idea? Link to comment https://forums.phpfreaks.com/topic/197334-echoing-in-wrong-place/#findComment-1035869 Share on other sites More sharing options...
TeddyKiller Posted April 2, 2010 Share Posted April 2, 2010 I understand you need help with this. But PLEASE do not bump messages. It is annoying. but in index.php, why dont you just call insertt() instead of go first? It's stupid. Also, I'll need some more of your index.php to find out where the echo is being displayed, and where it should be. Link to comment https://forums.phpfreaks.com/topic/197334-echoing-in-wrong-place/#findComment-1035875 Share on other sites More sharing options...
hackalive Posted April 2, 2010 Author Share Posted April 2, 2010 TeddyKiller I appreciated what you are saying but is there a way to get a file other than using require_once, the file structure must remain as is, just need a new way for require_once Link to comment https://forums.phpfreaks.com/topic/197334-echoing-in-wrong-place/#findComment-1035888 Share on other sites More sharing options...
TeddyKiller Posted April 2, 2010 Share Posted April 2, 2010 include() Link to comment https://forums.phpfreaks.com/topic/197334-echoing-in-wrong-place/#findComment-1035890 Share on other sites More sharing options...
hackalive Posted April 2, 2010 Author Share Posted April 2, 2010 include yields the same result as require Link to comment https://forums.phpfreaks.com/topic/197334-echoing-in-wrong-place/#findComment-1035892 Share on other sites More sharing options...
TeddyKiller Posted April 2, 2010 Share Posted April 2, 2010 Then remove your require or whatever, and put in the echo directly the function. What can go wrong? Link to comment https://forums.phpfreaks.com/topic/197334-echoing-in-wrong-place/#findComment-1035894 Share on other sites More sharing options...
hackalive Posted April 2, 2010 Author Share Posted April 2, 2010 SOLVED and incase anyone everneeds it in the future where I had require_one do this instead http://www.acuras.co.uk/articles/88-php-include-a-file-and-store-contents-to-variable-using-output-buffer Thanks to everyone who offered adive and help Link to comment https://forums.phpfreaks.com/topic/197334-echoing-in-wrong-place/#findComment-1035900 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.