jukie Posted June 16, 2013 Share Posted June 16, 2013 Hi, I developed a practise website so I can learn databases. I created a login system and when the user logged in, the PHP would welcome the user by using their username using sessions, now this worked perfect for me locally, so I uploaded the site to a web hosting, change the database settings and created new databases. When I try to login, its just keeps loading the login page and nothing happening. The database settings and queries are correct. If it worked locally, shouldn't this work on web hosting. I'm not sure on how to tackle this issue. Quote Link to comment https://forums.phpfreaks.com/topic/279236-sessions-local-v-hosting/ Share on other sites More sharing options...
mac_gyver Posted June 16, 2013 Share Posted June 16, 2013 unless your development system was identical to your live server, there's at least 5-10 different things that could cause a script to not work when moving between different server configurations or to a lesser extent, different versions of php/mysql. most likely your development system is setup with and you are using some of php's short-cuts that result in non-portable code. you need to troubleshoot what your code is doing so that you can find what is causing it. if you want us to help with that, you would need to post the relevant code needed to reproduce the problem. Quote Link to comment https://forums.phpfreaks.com/topic/279236-sessions-local-v-hosting/#findComment-1436256 Share on other sites More sharing options...
jukie Posted June 16, 2013 Author Share Posted June 16, 2013 Thank you for your reply. what is the best way of dealing with this to prevent this from happening. I'm using Go Daddy for hosting and its not quite as simple for me for editing on the go. When I choose to view/edit the file and its gives me notepad, I've tried to change the editor to net beans but struggling. What is the best process for a smooth transition from locally to web hosting. I'm getting an error which is in the login process Parse error: syntax error, unexpected T_STRING in D:\Hosting\10624400\html\logincheck.php on line 7 Line 7 is session_start(); Not much to go on Quote Link to comment https://forums.phpfreaks.com/topic/279236-sessions-local-v-hosting/#findComment-1436258 Share on other sites More sharing options...
jukie Posted June 16, 2013 Author Share Posted June 16, 2013 I now get no error and the login process does nothing, just keeps reloading the index page here the full code of the login check <?php session_start(); // dBase file include "connection.php"; $host = ''; $user = ''; $password = ''; $database = ''; $conn = mysql_connect($host,$user,$password) or die('Server Information is not Correct'); mysql_select_db($database,$conn) or die('Database Information is not correct'); // Inialize session session_start(); // Include database connection settings // Retrieve username and password from database according to user's input $login = mysql_query("SELECT * FROM gotusers WHERE (Username = '" . mysql_real_escape_string($_POST['Username']) . "') and (Password = '" . mysql_real_escape_string(md5($_POST['Password'])) . "')"); // Check username and password match if (mysql_num_rows($login) == 1) { // Set username session variable $_SESSION['Username'] = $_POST['Username']; // Jump to secured page header('Location: sucess.php'); } else { // Jump to login page header('Location: index.php'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/279236-sessions-local-v-hosting/#findComment-1436259 Share on other sites More sharing options...
jukie Posted June 16, 2013 Author Share Posted June 16, 2013 (edited) Its seems to be linked to this errorParse error: syntax error, unexpected T_STRING in D:\Hosting\10624400\html\logincheck.php on line 5 which is my password for the database, and the password is correct line 5 is $password = 'xxxxxxxx' Ive just fixed the above error , it was just a coma missing but now just reloading the index.php page. Must be the query. Edited June 16, 2013 by jukie Quote Link to comment https://forums.phpfreaks.com/topic/279236-sessions-local-v-hosting/#findComment-1436260 Share on other sites More sharing options...
jukie Posted June 17, 2013 Author Share Posted June 17, 2013 (edited) Hope someone can help with this, its driving me mad. The database connections are correct. Now I've put it down to the query that is being used. Now this query worked in local. It would be easier if it produce an error but it just reloading the index page. I've even just changed the engine using this query. ALTER TABLE tablename ENGINE = INNODB and it didn't sort it. Edited June 17, 2013 by jukie Quote Link to comment https://forums.phpfreaks.com/topic/279236-sessions-local-v-hosting/#findComment-1436335 Share on other sites More sharing options...
trq Posted June 17, 2013 Share Posted June 17, 2013 What is the relevant error and code now? Quote Link to comment https://forums.phpfreaks.com/topic/279236-sessions-local-v-hosting/#findComment-1436363 Share on other sites More sharing options...
jukie Posted June 17, 2013 Author Share Posted June 17, 2013 I can login in now, had to change the code from what worked in local to this local code $login = mysql_query("SELECT * FROM members WHERE (Username = '" . mysql_real_escape_string($_POST['Username']) . "') and (Password = '" . mysql_real_escape_string(md5($_POST['Password'])) . "')"); // Check username and password match if (mysql_num_rows($login) == 1) { // Set username session variable $_SESSION['Username'] = $_POST['Username']; // Jump to secured page header('Location: sucess.php'); } else { // Jump to login page header('Location: index.php'); } Live Server code $Username = mysql_real_escape_string($Username); $Password = mysql_real_escape_string($Password); $login ="SELECT * FROM gotusers WHERE username='$Username' and password= '$Password'"; $result=mysql_query($login); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ But this new code just brings new problems such as sessions as they were working on the local code. What is annoying is that even the registration page that worked in local doesn't work when uploaded. I have been working on PHP 5.4 and go daddy is using 5.3, Don't know if that is the issue. Pain in the bum. Quote Link to comment https://forums.phpfreaks.com/topic/279236-sessions-local-v-hosting/#findComment-1436371 Share on other sites More sharing options...
trq Posted June 17, 2013 Share Posted June 17, 2013 The 2nd piece of code should not work on any version of php 5 unless some nitwit has seriously borked the configuration. If that is working on Godaddy, they are more fucked up than I thought. Time to change hosting providers. Quote Link to comment https://forums.phpfreaks.com/topic/279236-sessions-local-v-hosting/#findComment-1436372 Share on other sites More sharing options...
jukie Posted June 17, 2013 Author Share Posted June 17, 2013 which provider do you recommend? I would rather my first code worked on go daddy to be honest. Quote Link to comment https://forums.phpfreaks.com/topic/279236-sessions-local-v-hosting/#findComment-1436377 Share on other sites More sharing options...
trq Posted June 17, 2013 Share Posted June 17, 2013 I use aws for everything now days so don't really have any hosting recommendations sorry. We do have a sticky thread on the subject in the misc board though. Quote Link to comment https://forums.phpfreaks.com/topic/279236-sessions-local-v-hosting/#findComment-1436381 Share on other sites More sharing options...
jukie Posted June 17, 2013 Author Share Posted June 17, 2013 I've just signed up with free hosting just to test the local code and it works. Crazy stuff. Quote Link to comment https://forums.phpfreaks.com/topic/279236-sessions-local-v-hosting/#findComment-1436389 Share on other sites More sharing options...
mac_gyver Posted June 17, 2013 Share Posted June 17, 2013 you seem to be randomly changing your code, rather than actually troubleshooting what is causing the problem(s). you have posted code with different database table names, with and without hashing of the password value, with two different methods of forming the query string that produce an identical query string (except that you left out the hashing in one), with extra session_start() statements (which should have been producing errors), and with a few php syntax errors that are typo's on your part. you need to slow down and find and fix one problem at a time. if the 'live' server code you posted above in this thread actually logs you in, then that either means your code on your localhost development system wasn't actually doing what you think or you have also removed the hashing from your registration code or perhaps you are not posting your actual code in this thread. it's more likely that your session related problems are due to header errors, but you don't have php's error_reporting set to E_ALL and the errors are not being reported. Quote Link to comment https://forums.phpfreaks.com/topic/279236-sessions-local-v-hosting/#findComment-1436390 Share on other sites More sharing options...
jukie Posted June 18, 2013 Author Share Posted June 18, 2013 I had to change the code over due to it not working on go daddy, I've found a free hosting which allowed my code to work on their server, the database names were changed on purpose. But you are right, I do need to slow down and sort out issue by issue. Quote Link to comment https://forums.phpfreaks.com/topic/279236-sessions-local-v-hosting/#findComment-1436652 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.