usawh Posted May 19, 2010 Share Posted May 19, 2010 I have hosting with Godaddy.Com and I am having problems with sessions. I contacted them and the cannot figure out the problem. Here is the page I am working on http://www.classifiedsinhawaii.com/Login101/login-box.php when you login the session error message comes up. Has anyone seen this message before ? regards, usawh Quote Link to comment https://forums.phpfreaks.com/topic/202325-problem-with-sessions/ Share on other sites More sharing options...
usawh Posted May 20, 2010 Author Share Posted May 20, 2010 Does anyone know a good reliable hosting company. I am having too much problems with godaddy.com. I would like to be able to use fronpage on the hosting. regards, usawh Quote Link to comment https://forums.phpfreaks.com/topic/202325-problem-with-sessions/#findComment-1060888 Share on other sites More sharing options...
-Karl- Posted May 20, 2010 Share Posted May 20, 2010 Looks like a problem with your code, not a problem with Godaddy. Quote Link to comment https://forums.phpfreaks.com/topic/202325-problem-with-sessions/#findComment-1060894 Share on other sites More sharing options...
usawh Posted May 20, 2010 Author Share Posted May 20, 2010 Here is the code <?session_start(); $username = $_POST['username']; $password = $_POST['password']; if ($username&&$password) { $connect = mysql_connect('server','user','password') or die("couldn't connect "); mysql_select_db('hilo102') or die ("couldn't find db"); $query = mysql_query(" SELECT * FROM users WHERE username='$username'"); $numrows = mysql_num_rows($query); if ($numrows!=0) { while ($row = mysql_fetch_assoc($query)) { $dbusername = $row['username']; $dbpassword = $row['password']; } if ($username==$dbusername&&$password==$dbpassword) { echo'you are logged in click <a href="http://www.classifiedsinhawaii.com/Post-Ads/post-ads.php">here</a> to post ad'; $_SESSION['username']=$username; } else echo'incorrect password'; } else die('That user does not exist'); echo $numrows; } else die (' Please enter an username and password !'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/202325-problem-with-sessions/#findComment-1060897 Share on other sites More sharing options...
WeirdMystery Posted May 20, 2010 Share Posted May 20, 2010 Here is the code <?session_start(); $username = $_POST['username']; $password = $_POST['password']; if ($username&&$password) { $connect = mysql_connect('server','user','password') or die("couldn't connect "); mysql_select_db('hilo102') or die ("couldn't find db"); $query = mysql_query(" SELECT * FROM users WHERE username='$username'"); $numrows = mysql_num_rows($query); if ($numrows!=0) { while ($row = mysql_fetch_assoc($query)) { $dbusername = $row['username']; $dbpassword = $row['password']; } if ($username == $dbusername && $password == $dbpassword) { echo'you are logged in click <a href=\"http://www.classifiedsinhawaii.com/Post-Ads/post-ads.php\">here</a> to post ad'; //Must add backslashes $_SESSION['username']=$username; } else echo'incorrect password'; } else die('That user does not exist'); echo $numrows; } else die (' Please enter an username and password !'); ?> Cleaned up your code a bit. <?php session_start(); /* I would recommend reloacting the database connect code to another file and using require_once("filename") to include the file */ $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); if ($username && $password) { $connect = mysql_connect('server','user','password') or die("couldn't connect "); mysql_select_db('hilo102') or die ("couldn't find db"); $query = mysql_query("SELECT * FROM `users` WHERE `username` = '$username'"); $numrows = mysql_num_rows($query); if ($numrows != 0) { while ($row = mysql_fetch_assoc($query)) { /* I would recommend hashing the password on both sides to prevent hackers from getting the password. */ $dbusername = $row['username']; $dbpassword = $row['password']; } if ($username == $dbusername && $password == $dbpassword) { $_SESSION['username'] = $username; echo "You are logged in click <a href=\"http://www.classifiedsinhawaii.com/Post-Ads/post-ads.php\">here</a> to post an Ad"; } else { echo "Incorrect Password"; } } else { die("That User does not Exist"); } echo $numrows; } else { die (" Please enter an username and password !"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/202325-problem-with-sessions/#findComment-1060935 Share on other sites More sharing options...
usawh Posted May 20, 2010 Author Share Posted May 20, 2010 Hi Thanks, I tried to copy your code but it gets jumbled up. regards, usawh Quote Link to comment https://forums.phpfreaks.com/topic/202325-problem-with-sessions/#findComment-1060978 Share on other sites More sharing options...
usawh Posted May 20, 2010 Author Share Posted May 20, 2010 Hi, Could it be something with the php.ini file ? Here is the file: register_globals = off allow_url_fopen = on expose_php = Off max_input_time = 60 variables_order = "EGPCS" extension_dir = ./ upload_tmp_dir = /tmp precision = 12 SMTP = relay-hosting.secureserver.net url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=,fieldset=" [Zend] zend_extension=/usr/local/zo/ZendExtensionManager.so zend_extension=/usr/local/zo/4_3/ZendOptimizer.so Quote Link to comment https://forums.phpfreaks.com/topic/202325-problem-with-sessions/#findComment-1060986 Share on other sites More sharing options...
anups Posted May 20, 2010 Share Posted May 20, 2010 There must be some balnk space before <?php tag Try to remove it, and even if it doesn't solved try after enabling error_reporting(E_ALL) because there may be some notice in your code. If that also doesn't solve your problem then write ob_start() at first line. Quote Link to comment https://forums.phpfreaks.com/topic/202325-problem-with-sessions/#findComment-1060993 Share on other sites More sharing options...
PFMaBiSmAd Posted May 20, 2010 Share Posted May 20, 2010 You are getting output from line 1 of your file. Since the php code on line 1 is not producing any output, that means that either you have some characters in your file before the <?php tag or your file has been saved with UTF-8 encoding and the BOM (Byte Order Mark) characters that your editor placed at the start of the file is the output that is occurring that is preventing the header from working. Insure that there are no actual characters before the <?php tag in your file and insure that you save the file without the BOM if you are intentionally saving the file as a UTF-8 encoded file or save the file as an ANSI encoded file. Quote Link to comment https://forums.phpfreaks.com/topic/202325-problem-with-sessions/#findComment-1061075 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.