Hello guys, last time I learn php and make some scripts that work on my localhost, but not in a hosting which I use. Example:
checklogin.php:

<?php
ob_start();
	$host="";
	$username="";
	$password=""; 
	$db_name="";

mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword'];

$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM members WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count==1){
while($row = mysql_fetch_array($result, MYSQL_BOTH)){
	$myusername = $row['username'];
	session_register('myusername');
	$mypassowrd = $row['password'];
	session_register('mypassword');
	header("location:login_success.php");
	exit();
}
}
else {
echo "Wrong Username or Password";
}

ob_end_flush();
?>

login_success.php:

<?php
	$host="";
	$username="";
	$password=""; 
	$db_name="";

mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

session_start();
if(!session_is_registered(myusername)){
header("location:main_login.php");
}

	$myusername = preg_replace('#(^A-Za-z0-9)#i', '',  $_SESSION["myusername"]);
	$mypassword = preg_replace('#(^A-Za-z0-9)#i', '',  $_SESSION["mypassword"]);
	
	$myusername = stripslashes($myusername);
	$mypassword = stripslashes($mypassword);
	$myusername = mysql_real_escape_string($myusername);
	$mypassword = mysql_real_escape_string($mypassword);
	
	$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
	$result=mysql_query($sql);
	
	$count=mysql_num_rows($result);
	
	if($count==0){
		echo "not in db";
		exit();
		}
		
	

?>

Log of the serv is:
PHP Warning: Unknown: open(/var/php_sessions/sess_4a6f1b2dc34d7f3828d2692e924f4ad9, O_RDWR) failed: No such file or directory (2) in Unknown on line 0
PHP Warning: Unknown: Failed to write session data (files). Please verify
Where is the problem? And all gd scripts don't work, but server use latest gd libary :/
For example I use the exmaple of php.net:

<?php
// File and new size
$filename = 'test.jpg';
$percent = 0.5;

// Content type
header('Content-Type: image/jpeg');

// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;

// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);

// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Output
imagejpeg($thumb);
?>

Thanks a lot for any help! Have a nice day

Recommended Answers

All 9 Replies

Use $_SESSION, session_register() is deprecated.
For the second problem you should report the error that you get. But try to run:

echo extension_loaded('gd');

1 equals to true, so gd is loaded and working, 0 to false.

@cereal, thank you but now say this error:

PHP Warning: Unknown: Failed to write session data (files). Please verify
20110828T094227: domain/checklogin.php
PHP Fatal error: Can't use function return value in write context in /hermes/bosweb/web066/b668/ipg.domain/checklogin.php on line 28
28 line is :

$_SESSION('myusername')= $myusername;

New in the code:

while($row = mysql_fetch_array($result, MYSQL_BOTH)){
	$myusername = $row['username'];
	$_SESSION('myusername')= $myusername;
	$mypassowrd = $row['password'];
	$_SESSION('mypassword') = $mypassowrd;
	header("location:login_success.php");
	exit();
}

GD output is 1

Your GD script is fine, I tested and works and so it seems your first script. In my opinion is an hosting issue.

Check if the session folder/directory is writeable,
sometimes its headslap moments

PHP Warning: Unknown: Failed to write session data (files)

Hosting local storage (HDD) is out of space (full capacity), try to delete some files/data.

Hosting local storage (HDD) is out of space (full capacity), try to delete some files/data.

I'm with unlimited space, php version is 5.2.17, mysql is 5.0.91.
@almostbob, how do i check? I have access only to "/" folder

<?php phpinfo(); ?> where id you set the session data to write?

@almostbob, permissions of the folders is :
cgi-bin is 755
tmp is 755.
After change the permission of tmp to 775 I see this error log:

20110829T031840: domain/main_login.php 
PHP Warning:  session_start() [<a href='function.session-start'>function.session-start</a>]: open(/var/php_sessions/sess_78971e704d3440545fae98d4a4bc7d8d, O_RDWR) failed: No such file or directory (2) in /hermes/bosweb/web066/b668/ipg.domain/main_login.php on line 2 
PHP Warning:  Unknown: open(/var/php_sessions/sess_78971e704d3440545fae98d4a4bc7d8d, O_RDWR) failed: No such file or directory (2) in Unknown on line 0 
PHP Warning:  Unknown: Failed to write session data (files). Please verify  
20110829T031846: domain/login_success.php 
PHP Warning:  session_start() [<a href='function.session-start'>function.session-start</a>]: open(/var/php_sessions/sess_78971e704d3440545fae98d4a4bc7d8d, O_RDWR) failed: No such file or directory (2) in /hermes/bosweb/web066/b668/ipg.domain/login_success.php on line 5 
PHP Warning:  Unknown: open(/var/php_sessions/sess_78971e704d3440545fae98d4a4bc7d8d, O_RDWR) failed: No such file or directory (2) in Unknown on line 0 
PHP Warning:  Unknown: Failed to write session data (files). Please veri 
20110829T031847: domain/main_login.php 
PHP Warning:  session_start() [<a href='function.session-start'>function.session-start</a>]: open(/var/php_sessions/sess_78971e704d3440545fae98d4a4bc7d8d, O_RDWR) failed: No such file or directory (2) in /hermes/bosweb/web066/b668/ipg.domain/main_login.php on line 2 
PHP Warning:  Unknown: open(/var/php_sessions/sess_78971e704d3440545fae98d4a4bc7d8d, O_RDWR) failed: No such file or directory (2) in Unknown on line 0 
PHP Warning:  Unknown: Failed to write session data (files). Please verify

main_login.php:

<? 
session_start();
if(session_is_registered(myusername)){
header("location:login_success.php");
}
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<form name="form1" method="post" action="checklogin.php">
Username:
<input name="myusername" type="text" id="myusername"><br />
Password:
<input name="mypassword" type="password" id="mypassword"><br />
<input type="submit" name="Submit" value="Login">

</form>

</body>
</html>

checklogin.php:

<?php
ob_start();

include "ctdb.php";

$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword'];

$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM members WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count==1){
while($row = mysql_fetch_array($result, MYSQL_BOTH)){
	$myusername = $row['username'];
	$_SESSION['myusername'] = $myusername;
	$mypassowrd = $row['password'];
	$_SESSION['mypassword'] = $mypassowrd;
	header("location:login_success.php");
	exit();
}
}
else {
echo "Wrong Username or Password";
}

ob_end_flush();
?>

login_success.php:

<? 
include "ctdb.php";

session_start();
if(!session_is_registered(myusername)){
header("location:main_login.php");
}

	$myusername = preg_replace('#(^A-Za-z0-9)#i', '',  $_SESSION["myusername"]);
	$mypassword = preg_replace('#(^A-Za-z0-9)#i', '',  $_SESSION["mypassword"]);
	
	$myusername = stripslashes($myusername);
	$mypassword = stripslashes($mypassword);
	$myusername = mysql_real_escape_string($myusername);
	$mypassword = mysql_real_escape_string($mypassword);
	
	$sql="SELECT * FROM members WHERE username='$myusername' and password='$mypassword'";
	$result=mysql_query($sql);
	
	$count=mysql_num_rows($result);
	
	if($count==0){
		echo "not in db";
		exit();
		}
		
	

?>


<html>
<body>
Login Successful
</body>
</html>

ctdb.php is connect to db script.
I can't understand what going on.

Thanks you because without you I don't know what to do! (I mean all who gave their spare time to help me)

Member Avatar for diafol

Sounds like the session doesn't know where to open/write. Could it be a php.ini issue?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.