مشکل در session register

foranyone

Well-Known Member
سلام خدمت دوستان عزیز

این کد حسابی کلافم کرده رو لوکال درست جواب میده ولی رو سرور به sesson register خطا میده

:ممنون میشم اگه راهنماییم کنین:

کد:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fa" lang="fa"> 
<head>
<title>Amlak</title>
 <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta http-equiv="Pragma" content="no-cache" />
<link rel="stylesheet" href="../css/main.css" type="text/css" />
</head>
<body>
<?php
if(isset($_POST['login']))
{
  @require("includes/config.inc.php");
  $next_program="admin.php";
  $table_name='admin';
  $userName=$_POST[user_name];
  $link_id=mysql_connect($config_dbHost,$config_dbUser,$config_dbPassword);
  mysql_select_db($config_dbName,$link_id);
  $sql="SELECT userName FROM $table_name WHERE userName='$userName'";
  $result=mysql_query($sql,$link_id) or die("Couldn’t execute query 1");
  $num=mysql_num_rows($result);
  if($num==1)
    {
      $sql="SELECT userName,password FROM $table_name WHERE userName='$userName' AND password=MD5('$_POST[password]')";
      $result2=mysql_query($sql,$link_id) or die("Couldn’t execute query 2");
      $row=mysql_fetch_assoc($result2);
      if($row)
      {
	     session_register('auth');
		  $_SESSION['auth']="yes";
	     echo "<script>
	  redirect(\"$next_program\")
	  function redirect(URLStr) { location = URLStr; }
	  </script>";
	  }
	  else
	  {
	     echo "<b><center>Sorry, Wrong!</center></b>";
	  }
  }
  else if($num==0)
  {
  echo "<b><center>Sorry, Wrong!</center></b>";
  }
}
?>
<center>
<br />
<br />
<form action="index.php" method="post">

User<br />

<input type="text" name="user_name" class="txtbox">
<br /><br />
Password <br />
<input type="password" name="password" class="txtbox">
<br />
<input type="submit" name="login" value="Login" class="btn">
</form>
</center>
</body>
</html>
 

ziXet

مدیر انجمن PHP/MYSQL
سلام خدمت دوستان عزیز

این کد حسابی کلافم کرده رو لوکال درست جواب میده ولی رو سرور به sesson register خطا میده

:ممنون میشم اگه راهنماییم کنین:

کد:
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fa" lang="fa"> 
<head>
<title>amlak</title>
 <meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta http-equiv="pragma" content="no-cache" />
<link rel="stylesheet" href="../css/main.css" type="text/css" />
</head>
<body>
<?php
if(isset($_post['login']))
{
  @require("includes/config.inc.php");
  $next_program="admin.php";
  $table_name='admin';
  $username=$_post[user_name];
  $link_id=mysql_connect($config_dbhost,$config_dbuser,$config_dbpassword);
  mysql_select_db($config_dbname,$link_id);
  $sql="select username from $table_name where username='$username'";
  $result=mysql_query($sql,$link_id) or die("couldn’t execute query 1");
  $num=mysql_num_rows($result);
  if($num==1)
    {
      $sql="select username,password from $table_name where username='$username' and password=md5('$_post[password]')";
      $result2=mysql_query($sql,$link_id) or die("couldn’t execute query 2");
      $row=mysql_fetch_assoc($result2);
      if($row)
      {
	     session_register('auth');
		  $_session['auth']="yes";
	     echo "<script>
	  redirect(\"$next_program\")
	  function redirect(urlstr) { location = urlstr; }
	  </script>";
	  }
	  else
	  {
	     echo "<b><center>sorry, wrong!</center></b>";
	  }
  }
  else if($num==0)
  {
  echo "<b><center>sorry, wrong!</center></b>";
  }
}
?>
<center>
<br />
<br />
<form action="index.php" method="post">

user<br />

<input type="text" name="user_name" class="txtbox">
<br /><br />
password <br />
<input type="password" name="password" class="txtbox">
<br />
<input type="submit" name="login" value="login" class="btn">
</form>
</center>
</body>
</html>
برای 1001امین بار!
قبل از سشن چیزی به مرورگر نباید فرستاده بشه
 

foranyone

Well-Known Member
اینو میدونم ولی اینجا مشکل از اون نیست!!
!! مشکل از session register !!! چون global register تو سرور off هست کار نمی کنه!
 

foranyone

Well-Known Member
ربطش رو می تونین تو این لینک ببینین:



http://ir.php.net/function.session-register

به طور خلاصه :

If you want your script to work regardless of register_globals, you need to instead use the $_SESSION array as $_SESSION entries are automatically registered. If your script uses session_register(), it will not work in environments where the PHP directive register_globals is disabled.

لطفا کد رو بخونین و در صورا امکان راهنمائیم کنین.
 

I.NoBody

Active Member
شما قبل از استفاده از session_register بايد حتماً session_start رو فراخوني كرده باشي و اين فانكشن بايد قبل از ارسال هر كاراكتري به هدر فراخواني بشه
 

foranyone

Well-Known Member
امتحان می کنم ولی فکر می کنم مشکل بیشتر مربوط به global registe باشه تا مشکل ارسال هدر!
 

I.NoBody

Active Member
کد:
Caution: 
If you want your script to work regardless of register_globals, you need to instead use the $_SESSION array as $_SESSION entries are automatically registered. If your script uses session_register(), it will not work in environments where the PHP directive register_globals is disabled. 

register_globals: important note: 
Since PHP 4.2.0, the default value for the PHP directive register_globals is off. The PHP community encourages all to not rely on this directive but instead use other means, such as the superglobals. 

Caution: 
This registers a global variable. If you want to register a session variable from within a function, you need to make sure to make it global using the global keyword or the $GLOBALS[] array, or use the special session arrays as noted below. 

Caution: 
If you are using $_SESSION (or $HTTP_SESSION_VARS), do not use session_register(), session_is_registered(), and session_unregister(). 

This function returns TRUE when all of the variables are successfully registered with the session. 

If session_start() was not called before this function is called, an implicit call to session_start() with no parameters will be made. $_SESSION does not mimic this behavior and requires session_start() before use.
 

جدیدترین ارسال ها

بالا