dongyanhu5628 2013-08-11 05:56
浏览 32
已采纳

php表单:从注册表单中将用户带回上一页

Tried various solution from stack overflow and internet but none seems to be working. My php registration page is a modal window form. what I am looking for is to take the user back to the page from where he redirected to login form.

Register link:

    <a data-toggle="modal" href="#myModal" class="btn btn-primary btn-lg">SIGN UP</a>

Register processing:

<?php
ob_start();
session_start();
require_once("config.php");
require_once("all_functions.php");
$cust_email = stripslashes($_POST['cust_email']);
$cust_password = stripslashes($_POST['cust_password']););




$res = mysql_query("SELECT * FROM register WHERE cust_email = '$cust_email'");
if (mysql_num_rows($res)>0)
    {
    echo 'That email is already registered';
    exit;
    }
mysql_query("INSERT INTO register (`cust_email`, `cust_password`) 
VALUES
('$cust_email', '$cust_password')");
$_SESSION['valid_user'] = $cust_email;
    header("Location: http://tre.com/");
    exit;
?>

function to check user is logged in or not

<?php
function check_valid_user()
// see if somebody is logged in and notify them if not
{
global $_SESSION;
if (isset($_SESSION['valid_user']))
{
return $_SESSION['valid_user'];
}
else
{
return false;
}
}
?>
  • 写回答

2条回答 默认 最新

  • dongmie3526 2013-08-11 06:54
    关注

    You Can use $_SERVER['HTTP_REFERER'] to get the address from where user have registered and apply it in either of this ways to directly take user back to previous page from register form without giving any message use

    header("Location:" . $_SERVER['HTTP_REFERER']);
    

    but if you want to display an message you can use this code

    echo '<meta http-equiv=REFRESH CONTENT="0; url='.$_SERVER['HTTP_REFERER'].'">
     Your registration was sucessfull you will be redirected automatically. If not, please <a href="'.$_SERVER['HTTP_REFERER'].'">click here</a>.';
    

    Hope it Helped

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错