Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

PHP sessions variables, Login, not working in remote server, very weird problem Need Help!. it's urgent?

My problem is:

I programed a website in dreamweaver CS4 and using wampp server in localhost PHP, everything works awesome, i have a login page where user inputs username and password and hits connect and it connects perfectly.

Now... i uploaded my website to de Internet (remote server) Live!!! and now i tried to connect with a username and nothing, the database works perfect but here is the weird thing. i got my code

if (!isset($_SESSION)) {

session_start();

}

with this, there is no user login. it doesnt work, but when i put this:

if (!isset($_SESSION)) {

session_start();

$sess = session_save_path();

echo $sess;

}

It connects to a user account, it works. but because of the echo.. then an error message comes out. Warning: Cannot modify header information - headers already sent by (output started at... if I eliminate the echo, no session variable working(doesn't work), if i put the same echo anywhere else it doesnt work. what's wrong with these ?? i can't seem to find a solution. Please help.

Update:

I know i cant print anything before head but the sessions work when i print that echo, otherwise i dosn't work. how come? if i comment the echo it dosnt work i cant login if i uncomment it the i can log in but the error appears =(.

2 Answers

Relevance
  • 1 decade ago

    First of all, do not use " if (isset($_SESSION)) ": it is ALWAYS set, (like $_POST and $_GET): It is Super_global!

    Just put session_start() at the very beginning of your code (before <!doctype...>). [full stop!]

    Do not echo anything either.

    I have found that too many users use $_SESSION the wrong way, and keep loosing it as they go along in their code. For this reason, when a user logs-in, I store their "session" (an MD5 random code) in the database. Much easier, much more secure! (Don't forget about hacking: Hackers CAN grab the $_SESSION variable. If you use another name, how can they find out? I never use the name "session")

    Now, without having your code, I can't tell you where you got it wrong, sorry!

  • 1 decade ago

    one thing that is different on web servers than the wamp server, nothing can be printed before going using the header() function

    all the header functions have to be before anything is echoed or printed

    it looks like you have other issues than what is here, you say it doesn't connect with the first block of code but it does with the second, but there shouldn't be any difference

    also connecting to a session is not the same as connecting to a database, you can check and see if the session is working by using a print_r function

Still have questions? Get your answers by asking now.