Jump to content
Larry Ullman's Book Forums

From My Computer To Server Problems


Recommended Posts

Hi, every one.

I developed my web page in my computer using XAMPP. Everything was working fine until i moved to the server. Now i having the following problems.

At the top of my page i got the following warning.

Warning: session_start() [function.session-start]: open(/temp/sess_3e23bd83a0025df302a789c7e4f9789f, O_RDWR) failed: No such file or directory (2) in /home/theevent/public_html/index.phpon line 2

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/theevent/public_html/index.php:2) in/home/theevent/public_html/index.php on line 2

That's one of my problems. The second problem that i having is that when i login from the login page instead of being redirected to the home page (index.php) i stay at the login page. But i know the session is working because i get the welcome message with the user name at the banner where i configured to be. If some have this problem before, please shed some light. Thanks.

Link to comment
Share on other sites

You must make sure that the very first thing you send to the browser is session call. No html or white space. I would guess this is why your getting the header warning. Let me know how that helps. Probably best you paste your code in future, so its easier to reference and debug ;)

  • Upvote 1
Link to comment
Share on other sites

Actually, the first error indicates that /temp doesn't exist on the server (or maybe isn't writable by you). Are you using any custom session settings? If not, it sounds like a php configuration problem on the server side. Is the server running windows, linux, unix? You can try other paths using session_save_path before your session_start call (http://php.net/manual/en/function.session-save-path.php). If the server is running unix/linux, I would try using /tmp or /var/tmp as the session save path. If that fails, get in contact with the sysadmin. Or, if you're the sysadmin, give us some more information about the system, and we can try to help.

 

 

The second error is because the first error generates output, which will cause all kinds of header troubles. But once you resolve the first error, the second should also go away.

 

Hope that helps.

-matthaus

  • Upvote 1
Link to comment
Share on other sites

Thanks for the reply jonathon and matthaus, i solve the session problem and like you said matthaus, it was my php.ini configuration. But now the problem i having is that when i login, instead of being redirect to the index.php page like i suppose to, i get logged in but don't get redirect to the index.php. i stay in the login_page, as loggedin. I did not have any problem when i was developing my web page on my machine, the script was working fine. I starting to suspect that the absolute_url($pages = "../index.php"), is the problem.

function absolute_url( $pages = "../index.php"){
//start defining the url
//url is http:// plus the host name plus the current directory:

$url = 'http://'. $_SERVER['HTTP_HOST']. dirname($_SERVER['PHP_SELF']);

///remove any trailing slashes
$url = rtrim($url, '/\\');

//add the page
$url .= '/' . $pages;

//return the url
return $url;
}//end of absolute function  

 

 

I don't know if this have to be modify when move from my machine to the server. But if i logout, i get redirected to the index.php like suppose to even though i'm using the same function absolute_url("../index.php"). The bellow script is the logout.

 session_start(); //access the existing session

//if no sssion variable exist redirect the user:
if(!isset($_SESSION['user_name']) ){
require_once("login_function_inc.php");
$url = absolute_url();
header("Location: $url");
exit();
}else{//cancel the session
   $_SESSION = array(); //clear the variable
session_destroy(); //destroy the session itself.
setcookie('PHPSESSID', '', time()-3600*24*7*365, '/', '', 0, 0); //destroy the cookie.
require_once("login_function_inc.php");
$url= absolute_url();
header("Location: $url");
exit();
} 

Or could it be that i have to keep modifying the php.ini file, and is so, to what path or section of the file should i modify . Thanks in advance.

Link to comment
Share on other sites

I'll take a stab at this one.

 

First off, when you use ../ for a directory path, you're telling the system to go to the parent directory of your current directory (i.e., the directory in which your current script is being executed). As such, if you change "../index.php" to just "index.php", it'll probably work. But again, that depends on your directory structure. Assuming that your index.php file is stored directly below the path stored in $_SERVER['PHP_SELF'], it should work.

 

As for while the logout script is working, well, if you look at your call to absolute_url, you're not sending any arguments, in which case the following is returned:

 

'http://' + $_SERVER['HTTP_HOST'] + dirname($_SERVER['PHP_SELF']) + '/'

 

While that's just a path, and not a file name, remember that if there is either an index.html or index.php file in that directory, that file will be automatically loaded without having to specify the file name. For example, if I had an index.php file in the following path:

 

http://www.example.com/scripts/index.php

 

I could load that index.php file by simply typing the following in my URL bar:

 

http://www.example.com/scripts/

 

And most likely, the same thing is happening in your logout script. I could be wrong, but after looking at your code real quick, that's what I'm thinking is the issue.

 

Please let us know if that helps. Thanks.

  • Upvote 1
Link to comment
Share on other sites

Thanks HartleySan for the reply. I did exactly what you told me and didn't solve the problem. Actually when i changed the path from '../index.php' to 'index.php', and try to logout, it won't find the page, that is the index.php. One thing that i noticed in the browser is the follow.

www.example.com/user_php/login_page_inc.php 

. This is path to the login page when i click to sign In.

 

And this is where i take me after loggedin

www.example.com/user_php/login.php

. As you can see instead of redirecting me to the index.php i get redirected to login.php. And as you know that where the absolute_url() function is declared. Any ideas. Thanks for you help.

Link to comment
Share on other sites

Sorry. I somewhat misspoke. When you call the absolute_url function without any arguments, it defaults to "../index.php". Sorry. That's my bad.

 

Because you issue is very much dependent on your specific environment, try outputting the final value of $url to the screen without redirecting the page, and see what it is. After you see what URL is being called, I bet it'll be obvious what the issue is. Something about that ../ part seems odd to me, but I don't have the book in front of me at the moment to confirm what Larry does.

  • Upvote 1
Link to comment
Share on other sites

Ok guys this is what happened.

 

earlier i modified the login.php to get the value of a variable and base on that variable either go to the index.php or to the URL store in that variable. The below code was the modification that i made.

  if($check){// if ok	
  		session_start();
  		$_SESSION['member_id'] = $data["member_id"];
  		$_SESSION['user_name'] = $data["user_name"];


  		$_SESSION['agent'] = md5($_SERVER['HTTP_USER_AGENT']);


 		/*setcookie('member_id',$data['member_id'], time()+3600*24*7*365, '/','', 0, 0 );
 		setcookie('user_name', $data['user_name'], time()+3600*24*7*365, '/','',0 ,0);
 		*/

 		//redirect to  the request page
  	if(isset($page_name)){
		$url= $page_name;
		header("Location: $url");
		$url= "../index.php";
		header("location: $url",false);
		exit();
 	}//end of isset

	}else{ //unsuccessful!
  	//assign $data to $errors for error reporting
  	//in the login_page_inc.php.
  	$errors = $data;	
}  

And the original script base on the book is as follows.

 if($check){// if ok	
  		session_start();
  		$_SESSION['member_id'] = $data["member_id"];
  		$_SESSION['user_name'] = $data["user_name"];


  		$_SESSION['agent'] = md5($_SERVER['HTTP_USER_AGENT']);



  		$url = absolute_url("../index.php");
  		header("Location: $url");
  		exit();




	}else{ //unsuccessful!
  	//assign $data to $errors for error reporting
  	//in the login_page_inc.php.
  	$errors = $data;	
} 

I tried the original script, base on the book and it works, after login i get redirected to the index.php. But the first script, the modified one, redirected the user back to requested page base on the $page_name URL value. So now i need a way to redirect the users to requested page using another script. That means more work. Any ideas how to do this the easy way. I don't understand how this script was working in my machine and when moved to the serve, do not. Thanks for you help guy, i appreciated.

Link to comment
Share on other sites

Without looking at your code (sorry, but I don't have the time at the moment), I can say the following:

 

The header("Location: $url"); function simply jumps to the URL stored in $url. For example, if $url is equal to http://www.amazon.com, that's where the page is going to go. The fact that it worked on your local machine, but is not working on a server simply suggests that the $url is no longer correct/exists.

 

As I suggested before, I would simply echo the final value stored in $url, and compare that to what the path should be for the URL of index.php (or whatever file you want to jump to), and do whatever is necessary so that the path is correct.

 

For example, let's say we have the following site structure:

 

http://www.example.com/index.php

http://www.example.com/add_user.php

http://www.example.com/edit_user.php

 

And you want the script to jump to index.php, unless one of the other two pages is set in a variable. Simply do the following:

 

if (isset($page_name)) {

 $url = 'http://www.example.com/' . $page_name;

} else {

 $url = 'http://www.example.com/index.php';

}

header("Location: $url");

exit();

 

Is that what you want to do?

 

Just remember that the server is not doing anything differently from your local machine in regards to the header() function. Just know that the path to the file might be different, which you need to account for.

 

Without more specific information, we cannot really help you, though. Sorry.

  • Upvote 1
Link to comment
Share on other sites

Hi, every one i found this article from the old forum from pswason, and i tried on my local machine before and i couldn't get it to work but i tried on the remote server and that took care of my problem. To redirect users base on the request page. For the example if user want to post an not loggedin, redirect to logi_page_inc.php.

This is the script to how redirect users base on the requested page. http://www.larryullm.com/forum/read.php?19,46857,46885.

In order for this code to work you have to delete the header redirect on the login.php. From this script

if($check){// if ok	
  		session_start();
  		$_SESSION['member_id'] = $data["member_id"];
  		$_SESSION['user_name'] = $data["user_name"];


  		$_SESSION['agent'] = md5($_SERVER['HTTP_USER_AGENT']);

 		/*setcookie('member_id',$data['member_id'], time()+3600*24*7*365, '/','', 0, 0 );
 		setcookie('user_name', $data['user_name'], time()+3600*24*7*365, '/','',0 ,0);
 		*/
 		//redirect
	$url = absolute_url("index.php");
		header("Location: $url");
  	exit();
}

To

 if($check){// if ok	
  		session_start();
  		$_SESSION['member_id'] = $data["member_id"];
  		$_SESSION['user_name'] = $data["user_name"];


  		$_SESSION['agent'] = md5($_SERVER['HTTP_USER_AGENT']);

 		/*setcookie('member_id',$data['member_id'], time()+3600*24*7*365, '/','', 0, 0 );
 		setcookie('user_name', $data['user_name'], time()+3600*24*7*365, '/','',0 ,0);
 		*/

                 make no redirection here so the code on the login_page_inc.php redirect the requested page.
 	}

If some one have trouble in getting this script to work, feel free to ask. Or post the issue.

  • Upvote 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...