Jump to content

Sessions Local V Hosting


jukie

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :confused:

Link to comment
Share on other sites

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');
 }

  
 
  


?>
Link to comment
Share on other sites

Its seems to be linked to this error
Parse 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 by jukie
Link to comment
Share on other sites

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 by jukie
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.