EchoFool Posted November 16, 2008 Share Posted November 16, 2008 On my script on the main page which is login.php say the domain was www.test.com/login.php if some one changes that url to: www.test.com/login.php/css The script crashes and i have no idea how that happens? This is the error i get when a user changes the url to that: Notice: A session had already been started - ignoring session_start() in session.php on line 2 Warning: Cannot modify header information - headers already sent by (output started at session.php:2) in session.php on line 4 surely login.php/css is an invalid url ? But it seems to not give a "cannot find url" error that i was hoping it would =/ Quote Link to comment https://forums.phpfreaks.com/topic/132962-script-crashes-with-url-alteration/ Share on other sites More sharing options...
wildteen88 Posted November 16, 2008 Share Posted November 16, 2008 The error is caused becuase session_start() is being called twice. It should only be call once. surely login.php/css is an invalid url ? No its a perfectly valid url. Quote Link to comment https://forums.phpfreaks.com/topic/132962-script-crashes-with-url-alteration/#findComment-691434 Share on other sites More sharing options...
PFMaBiSmAd Posted November 16, 2008 Share Posted November 16, 2008 Doing that causes several server variables to contain the /css at the end - [REQUEST_URI] => /login.php/css [PATH_INFO] => /css [PATH_TRANSLATED] => your_path\htdocs\css [php_SELF] => /login.php/css Is your login.php code using any of those or are you doing any URL rewriting? Quote Link to comment https://forums.phpfreaks.com/topic/132962-script-crashes-with-url-alteration/#findComment-691441 Share on other sites More sharing options...
EchoFool Posted November 17, 2008 Author Share Posted November 17, 2008 Argh it is checking to see if such a url exists and if it does do not load a session as one is already set. But then, if the url changes the if statement would fail and then two session start's are set... which is what must be causing the error. How can i prevent the crash though? Quote Link to comment https://forums.phpfreaks.com/topic/132962-script-crashes-with-url-alteration/#findComment-692062 Share on other sites More sharing options...
revraz Posted November 17, 2008 Share Posted November 17, 2008 Fix your code... session_start doesn't need a IF statement, it will start one if one does not exist or resume one that does exist. Quote Link to comment https://forums.phpfreaks.com/topic/132962-script-crashes-with-url-alteration/#findComment-692063 Share on other sites More sharing options...
PFMaBiSmAd Posted November 17, 2008 Share Posted November 17, 2008 If a page uses sessions, you should have one session_start() at the start of the main file. You should not have session_start() statements in multiple bits of included code or in conditional statements. Quote Link to comment https://forums.phpfreaks.com/topic/132962-script-crashes-with-url-alteration/#findComment-692066 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.