Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial php 页面跳转 本地windows 环境正常,上传linux 服务器上跳转不了

php 页面跳转 本地windows 环境正常,上传linux 服务器上跳转不了

Jun 23, 2016 pm 01:52 PM
php upload server environment Jump

php 做的一个下项目,登录后页面跳转到首页,在本地的Windows 环境是正常的,上传到linux服务器上就跳转不了。求解答。
代码,项目结构如下:

action/loginin.php

//user loginif (isset($_POST['username']) && isset($_POST['password'])		&& !empty($_POST['username']) && !empty($_POST['password'])) {	try{	$username = $_POST['username'];	$password = $_POST['password'];	$rs = $config[DAOIMPL]->getLoginByName($username);	$arr = mysql_fetch_array($rs);	//echo $arr['sys_user_passwd'];	if ($arr && $arr['sys_user_passwd'] == generateUserPassword($password)) {		$_SESSION[SESSIONUSER] = $username;		echo '<script language=javascript>window.location="../index.php"</script>';//跳转到根目录下的index.php	}else {		echo "<script language=javascript>alert('用户名或密码不正确,请重新输入!'); window.location='../login.php'</script>";		exit(0);	}	}	catch (Exception $e){		echo "<script language=javascript>alert('".$e."'); window.location='../login.php'</script>";		exit(0);	}}
Copy after login





另外服务器是 操作系统:Ubuntu 12.04 64位


回复讨论(解决方案)

跳转不了的表现是什么呢?网页不存在?还是脚本没反应?

1、你的传统代码不会抛出异常,所以你的异常处理是无效的,可以删去。或许就是他的原因
2、url 跳转宜使用绝对路径
location="/index.php"

跳转不了的表现是什么呢?网页不存在?还是脚本没反应?



Js 脚本没反应。

在登录成功代码里加了一个alert
if ($arr && $arr['sys_user_passwd'] == generateUserPassword($password)) {
$_SESSION[SESSIONUSER] = $username;
echo '';
echo '';
}else {
echo "";
exit(0);
}

效果是:


点击确认后,重新回到登录界面了

文件名大小写一致么?windows默认是不区分大小写的,linux是区分大小写的。另外,你直接访问那个php,看是否能访问?
或者,你些一个静态的html文件,放到 loginin.php 相同位置,把 loginin.php里面的js拷贝进去测试,看能否正常跳转?

重新回到登录界面 不一定是你没有跳转到index.php,有可能是你的session没有注册成功,到index.php又转到login.php了。

你在index.php最前面放置一些输出信息,看是否有访问过index.php

?log看看程序走到哪?,再?定??。

//user loginif (isset($_POST['username']) && isset($_POST['password'])        && !empty($_POST['username']) && !empty($_POST['password'])) {    echo '1';    try{    $username = $_POST['username'];    $password = $_POST['password'];    $rs = $config[DAOIMPL]->getLoginByName($username);    $arr = mysql_fetch_array($rs);    //echo $arr['sys_user_passwd'];    echo '2';    if ($arr && $arr['sys_user_passwd'] == generateUserPassword($password)) {        $_SESSION[SESSIONUSER] = $username;        echo '3';        echo '<script language=javascript>window.location="../index.php"</script>';//跳转到根目录下的index.php    }else {        echo '4';        echo "<script language=javascript>alert('用户名或密码不正确,请重新输入!'); window.location='../login.php'</script>";        exit(0);    }    }    catch (Exception $e){        echo '5';        echo "<script language=javascript>alert('".$e."'); window.location='../login.php'</script>";        exit(0);    }}
Copy after login
Copy after login

1、你的传统代码不会抛出异常,所以你的异常处理是无效的,可以删去。或许就是他的原因
2、url 跳转宜使用绝对路径
location="/index.php"



根据你的意见,我把代码做了修改,但还是不能跳转,登录成功后返回到了登录界面

if (isset($_POST['username']) && isset($_POST['password'])
&& !empty($_POST['username']) && !empty($_POST['password'])
) {
//try{
$username = $_POST['username'];
$password = $_POST['password'];
$rs = $config[DAOIMPL]->getLoginByName($username);
$arr = mysql_fetch_array($rs);
//echo $arr['sys_user_passwd'];
if ($arr && $arr['sys_user_passwd'] == generateUserPassword($password)) {
$_SESSION[SESSIONUSER] = $username;
echo '';
echo '';
}else {
echo "";
//exit(0);
}
//}
//catch (Exception $e){
//echo "";
//exit(0);
//}
}

有可能是你的session没有注册成功,到index.php页面之后,判断没有登录,又往登录界面跳转了。你先屏蔽index.php的跳转功能试试看。

?log看看程序走到哪?,再?定??。

//user loginif (isset($_POST['username']) && isset($_POST['password'])        && !empty($_POST['username']) && !empty($_POST['password'])) {    echo '1';    try{    $username = $_POST['username'];    $password = $_POST['password'];    $rs = $config[DAOIMPL]->getLoginByName($username);    $arr = mysql_fetch_array($rs);    //echo $arr['sys_user_passwd'];    echo '2';    if ($arr && $arr['sys_user_passwd'] == generateUserPassword($password)) {        $_SESSION[SESSIONUSER] = $username;        echo '3';        echo '<script language=javascript>window.location="../index.php"</script>';//跳转到根目录下的index.php    }else {        echo '4';        echo "<script language=javascript>alert('用户名或密码不正确,请重新输入!'); window.location='../login.php'</script>";        exit(0);    }    }    catch (Exception $e){        echo '5';        echo "<script language=javascript>alert('".$e."'); window.location='../login.php'</script>";        exit(0);    }}
Copy after login
Copy after login



已经运行到登录成功代码处,3楼有贴运行现象

if (isset($_POST['username']) && isset($_POST['password']) && !empty($_POST['username']) && !empty($_POST['password'])) {  $username = $_POST['username'];  $password = $_POST['password'];  $rs = $config[DAOIMPL]->getLoginByName($username);  $arr = mysql_fetch_array($rs);  if ($arr && $arr['sys_user_passwd'] == generateUserPassword($password)) {    $_SESSION[SESSIONUSER] = $username;    echo '<script language=javascript>alert("验证成功")</script>';    echo '<script language=javascript>window.location="/cloudsong/index.php"</script>';  }else {    echo "<script language=javascript>alert('用户名或密码不正确,请重新输入!'); window.location='/cloudsong/login.php'</script>";  }}
Copy after login
Copy after login
如果登录成功,会弹出“验证成功”对话框,你有吗?

有可能是你的session没有注册成功,到index.php页面之后,判断没有登录,又往登录界面跳转了。你先屏蔽index.php的跳转功能试试看。



session已经设置成功,屏蔽掉index.php的跳转后,程序就停在了logininphp

if (isset($_POST['username']) && isset($_POST['password']) && !empty($_POST['username']) && !empty($_POST['password'])) {  $username = $_POST['username'];  $password = $_POST['password'];  $rs = $config[DAOIMPL]->getLoginByName($username);  $arr = mysql_fetch_array($rs);  if ($arr && $arr['sys_user_passwd'] == generateUserPassword($password)) {    $_SESSION[SESSIONUSER] = $username;    echo '<script language=javascript>alert("验证成功")</script>';    echo '<script language=javascript>window.location="/cloudsong/index.php"</script>';  }else {    echo "<script language=javascript>alert('用户名或密码不正确,请重新输入!'); window.location='/cloudsong/login.php'</script>";  }}
Copy after login
Copy after login
如果登录成功,会弹出“验证成功”对话框,你有吗?

 有,3楼的图就是登录后,弹出对话框的截图


有可能是你的session没有注册成功,到index.php页面之后,判断没有登录,又往登录界面跳转了。你先屏蔽index.php的跳转功能试试看。



session已经设置成功,屏蔽掉index.php的跳转后,程序就停在了logininphp

从你贴出来的loginin.php代码和运行情况来看,是不可能往 录界面跳转 跳转的,对吧? 屏蔽掉index.php的跳转后,程序就不再往登录界面跳转,这也就说明了一些问题。

你再在index.php最前面输出一些信息,看看情况如何?

那就是你没有 session_start() 了

?出session看看有什??西?

问题初步判断确实是出在我session 检查的代码里,谢谢大家帮忙分析!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles