Sericet Posted December 11, 2012 Share Posted December 11, 2012 Hey everyone, New to the forum and I php. I am using adobe muse to design my website which does not allow me to write code at the beginning of the document. Adobe muse exports all the files at HTML files and then I upload them. I am making a login system and I need to use sessions. I have the session working (I think). I set an variable session(email) and if this is set then echo welcome back. If it isn't set then i echoed the forms for a login. Problem I am having is when I go to a link on my page my page seems to lose my session. I am unable to write my php before any HTML code. Is this causing the problem? Quote Link to comment https://forums.phpfreaks.com/topic/271846-php-in-body/ Share on other sites More sharing options...
MDCode Posted December 11, 2012 Share Posted December 11, 2012 You're going to have to show something because I have no idea unless you are not using session_start(); to start the sessions Quote Link to comment https://forums.phpfreaks.com/topic/271846-php-in-body/#findComment-1398656 Share on other sites More sharing options...
Stooney Posted December 11, 2012 Share Posted December 11, 2012 First off, I dont think Adobe Muse is meant for any sort of server side scripting. But, if you insist, just make sure you're running session_start(); anywhere before the points where you're trying to access session variables. Quote Link to comment https://forums.phpfreaks.com/topic/271846-php-in-body/#findComment-1398748 Share on other sites More sharing options...
Sericet Posted December 11, 2012 Author Share Posted December 11, 2012 Ok so, adobe muse doesn't allow me to write code at the beginning of the document. I opened it in dream weaver and put the code in before uploading it. Seems I need to have session strt at the VERY beginning of y code.... This is annoying to open it in dream weaver to add the code. Is there another option? Quote Link to comment https://forums.phpfreaks.com/topic/271846-php-in-body/#findComment-1398809 Share on other sites More sharing options...
RobertP Posted December 12, 2012 Share Posted December 12, 2012 another ide? maybe notepad++.. or check the template layouts, maybe you can change it yourself for that program Quote Link to comment https://forums.phpfreaks.com/topic/271846-php-in-body/#findComment-1398810 Share on other sites More sharing options...
kicken Posted December 12, 2012 Share Posted December 12, 2012 If you have the ability to change the php.ini file or change settings via .htaccess, you could enable output buffering as a work around. Quote Link to comment https://forums.phpfreaks.com/topic/271846-php-in-body/#findComment-1398811 Share on other sites More sharing options...
Sericet Posted December 12, 2012 Author Share Posted December 12, 2012 I don't want to use another IDE. My brother is artistic and is designing my site in muse. I'm am just throwing in some php to make the log in system. I do have access to the access file. Could you explain more about this? I'm very new to php. Quote Link to comment https://forums.phpfreaks.com/topic/271846-php-in-body/#findComment-1398812 Share on other sites More sharing options...
Jessica Posted December 12, 2012 Share Posted December 12, 2012 You will have to use an IDE meant for development. Quote Link to comment https://forums.phpfreaks.com/topic/271846-php-in-body/#findComment-1398822 Share on other sites More sharing options...
Sericet Posted December 12, 2012 Author Share Posted December 12, 2012 Why would I have to use another IDE? I have this thing reading an IPN from PayPal and recording all data to MySQL, sessions are working problem is I can't write the sessions at the very beginning of my page. My question is, is there another way to make sessions work without having it at the top of the page. Please explain why you think I need another IDE. Intelligent answers only please. Quote Link to comment https://forums.phpfreaks.com/topic/271846-php-in-body/#findComment-1398841 Share on other sites More sharing options...
KevinM1 Posted December 12, 2012 Share Posted December 12, 2012 First, snark like: Intelligent answers only please. only makes people not want to help. Now, people are telling you to use another IDE because, evidentally Adobe Muse isn't meant for PHP editing. Note that no one has suggwsted that your brother also switch IDEs. Since, apparently, Muse just outputs HTML (and likely CSS as well), there's no reason why your brother couldn't do his part in Muse and you do your part in something else. Right tool for the job and all that. Regarding PHP, I'm going to go out on a limb and guess that you learned what you know from a poor and/or dated resource (like w3schools, which NO ONE should go to). I'm also going to guess that the resource's examples highlighted PHP's ability to go between PHP code and HTML. I'm guessing this because you want to put PHP code in the body of your pages. That's exactly the wrong way to write PHP. The best way to write PHP is to do all your scripting upfront, store your results in variables, and then use as little PHP as possible in your HTML to echo those results. For you, this means all session and database work first. Now, to your actual problem - do you have session_start() on each page? Can you post your code? Quote Link to comment https://forums.phpfreaks.com/topic/271846-php-in-body/#findComment-1398853 Share on other sites More sharing options...
Sericet Posted December 12, 2012 Author Share Posted December 12, 2012 Ok, I am not going to be using another IDE. Question stated again: can you start a session without having it at the top of a page. Is there another way around this? Quote Link to comment https://forums.phpfreaks.com/topic/271846-php-in-body/#findComment-1399040 Share on other sites More sharing options...
Jessica Posted December 13, 2012 Share Posted December 13, 2012 NO. Quote Link to comment https://forums.phpfreaks.com/topic/271846-php-in-body/#findComment-1399053 Share on other sites More sharing options...
cyberRobot Posted December 13, 2012 Share Posted December 13, 2012 NO. For what it's worth, the following code works for me? <html> <head> <title>Test Session</title> </head> <body> <?php session_start(); if(isset($_SESSION['test'])) { print '<p>Session var found: ' . $_SESSION['test'] . '</p>'; } else { $_SESSION['test'] = 'hello'; print '<p>Session var now set to ' . $_SESSION['test'] . '</p>'; } ?> </body> </html> While digging through the PHP manual (http://php.net/manua...ssion-start.php), I didn't see any mention of session_start() needing to appear at the top. Based on the contributor notes, however, there are some comments where session_start() didn't work without it being at the top...so maybe it comes down to server configuration. Quote Link to comment https://forums.phpfreaks.com/topic/271846-php-in-body/#findComment-1399154 Share on other sites More sharing options...
MDCode Posted December 13, 2012 Share Posted December 13, 2012 For what it's worth, the following code works for me? It may work, but if you had error reporting on you would be getting an error message While digging through the PHP manual (http://php.net/manua...ssion-start.php), I didn't see any mention of session_start() needing to appear at the top. session_start(); must be called before any output or you get errors. Quote Link to comment https://forums.phpfreaks.com/topic/271846-php-in-body/#findComment-1399155 Share on other sites More sharing options...
cyberRobot Posted December 13, 2012 Share Posted December 13, 2012 It may work, but if you had error reporting on you would be getting an error message session_start(); must be called before any output or you get errors. I actually don't get any errors, notices, or warnings. <?php error_reporting(E_ALL); ini_set('display_errors', 1); ?> <html> <head> <title>Test Session</title> </head> <body> <?php session_start(); if(isset($_SESSION['test'])) { print '<p>Session var found: ' . $_SESSION['test'] . '</p>'; } else { $_SESSION['test'] = 'hello'; print '<p>Session var now set to ' . $_SESSION['test'] . '</p>'; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/271846-php-in-body/#findComment-1399158 Share on other sites More sharing options...
PFMaBiSmAd Posted December 13, 2012 Share Posted December 13, 2012 @cyberRobot, at the top of the page, means before you output anything to the browser - Note: To use cookie-based sessions, session_start() must be called before outputing anything to the browser. Your code worked, because php has a setting, mentioned by kicken in this thread, that hides incorrectly coded pages, but results in code that is not portable between different server configurations and should be avoided. Quote Link to comment https://forums.phpfreaks.com/topic/271846-php-in-body/#findComment-1399160 Share on other sites More sharing options...
cyberRobot Posted December 13, 2012 Share Posted December 13, 2012 @PFMaBiSmAd - Ah, I see the note now. Thanks for the clarification. Quote Link to comment https://forums.phpfreaks.com/topic/271846-php-in-body/#findComment-1399162 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.