Bueno ahora mismo estoy desarrollando un web con php (la primera que hago) y mi problema reside cuando la cuelgo en el servidor; vamos, que cuando lo ejecuto en local todo me funciona bien pero no cuando lo subo todo al servidor.
El problema he podido comprobar que es por la cosa de la sesion pero no llego a enteder el porque.
Para la sesion utilizo una clase en donde en el constructor incluyo la sentencia session_sart(). Dentro de mi clase sesion hay varias funciones donde pudes obtener variables de sesion, eliminar sesiones y otras funciones.
La conexion de la base de datos funciona bien y no es por ello.
Aqui os mando el codigo:
Código PHP:
<?php
require_once ("class.session.php");
require_once ("Connections/inc.connect_dets.php");
require_once ("class.dbConnect.php");
require_once ("class.Page.php");
// create the session object
$session_ID = new Session_db();
// connect to database server and open database
$link_id = new dbConnect($host_name, $user_name, $user_password, $database);
// link the sesion object to the database<a href="indexPersonal.php"></a>
$session_ID->set_db_link($link_id);
$userSession = $session_ID->get_session_var("logged_user_ID");
$body_title = "Looking for conexion to your account";
$page_title = "Selecting a user from the database";
$LogPass_query = "SELECT * FROM users WHERE idUser='$userSession'";
$resultLogPass = $link_id->query($LogPass_query);
if ($link_id->count_rows($resultLogPass)!=0)
{
$page_content = <<< PAGEOUT
You are logged on<a href="indexPersonal.php?userSession=$userSession">here</a>
to go your personal account / Connect with other user press<a href="listuser_destroysession.php">here</a>
PAGEOUT;
}
else
{
$body_title = "CONNECT TO YOUR ACOUNT";
$page_title = "Selecting a user";
$page_content = <<< PAGEOUT
<table class="tabla" align="center"><form method="post" action="getuserdetails.php">
<tr><td align="left"><strong>Login: </strong></td><td><input type="text" name="login"></td>
<tr><td align="left"><strong>Password: </strong></td><td><input type="password" name="password"></td>
<tr></tr>
<tr></tr>
<tr><td></td><td><input type="submit" value="Go to your account" class="boton"></td>
</form></table>
<br />
<div id="remindpassword">
<a href="remindPassword.php">Remind password</a> /
<a href="insertuserform.php">Create a new user</a>
</div>
PAGEOUT;
$output_page_obj = new Page($page_title, $page_content, $body_title);
$output_page = $output_page_obj->get_page();
echo $output_page;
?>
Tambien os mando la clase sesion
Código PHP:
<?php
class Session_db
{
private $c_local_db_link;
private $c_local_session_ID;
private $c_session_time_out = 600; // time figures are in seconds
private $c_session_life_time = 7200;
function __construct()
{
// reset the session name
session_name("My_Session");
// start the session and store the session ID in a cookie on the
// user's machine, or retrieve the cookie if it already exists
session_start();
// return the session ID and store it locally
$this->c_local_session_ID = session_id();
}
function set_db_link($p_db_link)
{
$this->c_local_db_link = $p_db_link;
// take the opportunity to delete expired session data
$this->delete_expired_session_data();
}
// assign the given value to the session variable
function set_session_var($p_session_var_name, $p_session_var_value)
{
$m_session_var_value = addslashes($p_session_var_value);
$m_query_string = "UPDATE Session ";
$m_query_string .= "SET Session_Value = '$m_session_var_value' ";
$m_query_string .= "WHERE Session_Key = '$this->c_local_session_ID' ";
$m_query_string .= "AND Session_Var_name = '$p_session_var_name'";
$m_query_result = $this->c_local_db_link->query($m_query_string);
return $m_query_result;
}
// create a session variable
function create_session_var($p_session_var_name, $p_session_var_value)
{
$m_session_var_value = addslashes($p_session_var_value);
// check to see if session variable already exists in the session table
if (!$this->check_session_var($p_session_var_name))
{
$m_query_string = "INSERT INTO Session ";
$m_query_string .= "SET Session_Key = '$this->c_local_session_ID', ";
$m_query_string .= "Session_Var_name = '$p_session_var_name', ";
$m_query_string .= "Session_Value = '$m_session_var_value' ";
$m_query_result = $this->c_local_db_link->query($m_query_string);
}
else
$m_query_result = $this->set_session_var($p_session_var_name, $m_session_var_value);
return $m_query_result;
}
// check if session var exists
function check_session_var($p_session_var_name)
{
$m_query_string = "SELECT Session_Var_name ";
$m_query_string .= "FROM Session ";
$m_query_string .= "WHERE Session_Key = '$this->c_local_session_ID' ";
$m_query_string .= "AND Session_Var_name = '$p_session_var_name'";
$m_query_result = $this->c_local_db_link->query($m_query_string);
$m_num_rows = $this->c_local_db_link->count_rows($m_query_result);
if ($m_num_rows > 0)
$m_result = TRUE;
else
$m_result = FALSE;
return $m_result;
}
// return the value from the session variable if it exists
function get_session_var($p_session_var_name)
{
$m_query_string = "SELECT Session_Value ";
$m_query_string .= "FROM Session ";
$m_query_string .= "WHERE Session_Key = '$this->c_local_session_ID' ";
$m_query_string .= "AND Session_Var_name = '$p_session_var_name'";
$m_query_result = $this->c_local_db_link->query($m_query_string);
if ((!$m_query_result) or ($m_query_result=NULL))
$m_result = $m_query_result;
else
{
$m_row = $this->c_local_db_link->fetch_array($m_query_result);
$m_result = $m_row['Session_Value'];
$m_result = stripslashes($m_result);
}
return $m_result;
}
// delete the given session variable
function delete_session_var($p_session_var_name)
{
$m_query_string = "DELETE FROM Session ";
$m_query_string .= "WHERE Session_Key = '$this->c_local_session_ID' ";
$m_query_string .= "AND Session_Var_name = '$p_session_var_name'";
$m_query_result = $this->c_local_db_link->query($m_query_string);
return $m_query_result;
}
// terminate the session
function destroy_session()
{
$m_query_string = "DELETE FROM Session ";
$m_query_string .= "WHERE Session_Key = '$this->c_local_session_ID'";
$m_query_result = $this->c_local_db_link->query($m_query_string);
$_SESSION = array();
session_destroy();
return $m_query_result;
}
// delete expired session data
function delete_expired_session_data()
{
// remove any session var that has exceeded session life time
$m_expiration_time = time() - $this->c_session_life_time;
$m_date_time_to_check = date('Y-m-d H:i:s', $m_expiration_time);
$m_query_string = "DELETE FROM Session ";
$m_query_string .= "WHERE Session_Created < '$m_date_time_to_check'";
$m_query_result = $this->c_local_db_link->query($m_query_string);
return $m_query_result;
}
}
// end of class Session_db
?>
y por ultimo la clase Conexion
Código PHP:
<?php
class dbConnect
{
// access is private for all class variables
private $c_host_name;
private $c_user_name;
private $c_user_password;
private $c_user_database;
private $c_db_link;
// class constructor
function __construct($p_host_name, $p_user_name, $p_user_password, $p_user_database)
{
$this->c_host_name = $p_host_name;
$this->c_user_name = $p_user_name;
$this->c_user_password = $p_user_password;
$this->c_user_database = $p_user_database;
$this->connect_to_database();
}
function connect_to_database()
{
// validate passed in values
if (empty($this->c_host_name) || empty($this->c_user_name)
|| empty($this->c_user_password) || empty($this->c_user_database))
{
trigger_error("<p>Invalid database connection values: </p>");
exit();
}
// attempt to connect to MySQL server & database
try
{
$this->c_db_link = new mysqli($this->c_host_name, $this->c_user_name,
$this->c_user_password, $this->c_user_database);
if (mysqli_connect_error())
throw new Exception("<p>Could not connect to MySQL server</p>");
}
catch (Exception $err)
{
trigger_error($err->getMessage());
exit();
}
}
// perform safe query
function query($p_query_to_perform)
{
if (empty($p_query_to_perform))
{
trigger_error("<p>No SQL query</p>");
exit();
}
else
{
try
{
if(!$m_result = $this->c_db_link->query($p_query_to_perform))
throw new Exception("<p>Error in SQL query</p>");
}
catch (Exception $err)
{
trigger_error($err->getMessage());
exit();
}
}
return $m_result;
}
// count number of returned rows in the record set
function count_rows($p_query_result)
{
$m_num_rows = $p_query_result->num_rows;
return $m_num_rows;
}
// count number of returned fields in the record set
function count_fields($p_query_result)
{
$m_num_fields = $p_query_result->num_fields;
return $m_num_fields;
}
// return the record set with field names
function fetch_array($p_query_result)
{
$m_row = $p_query_result->fetch_array(MYSQLI_ASSOC);
return $m_row;
}
// return the record set with field indices
function fetch_row($p_query_result)
{
$m_row = $p_query_result->fetch_row();
return $m_row;
}
// close the database link
function close_db_link()
{
$this->c_db_link->close();
}
} // end of class
?>
Cualquier ayuda es muy bien recibida
Alguien sabria o le ha pasado algo parecido????
Gracias de antemano...