Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php或jquery发送$\u GET_Php_Jquery_Forms_Html - Fatal编程技术网

使用php或jquery发送$\u GET

使用php或jquery发送$\u GET,php,jquery,forms,html,Php,Jquery,Forms,Html,my index.php页面有如下内容: if(isset($_GET['page'])) { switch ($_GET['page']) { case 'login': include('login.php'); break; case 'log_out': $_SESSION['loggedin'] = false;

my index.php页面有如下内容:

if(isset($_GET['page'])) {
        switch ($_GET['page']) {
            case 'login':
                include('login.php');
            break;
            case 'log_out':
                $_SESSION['loggedin'] = false;
                include('loggedout.html');
            break;
            case 'profile':
                include('profile.php');
            break;
            case 'contact_us':
                include('contact.html');
            break;
            default:
                include('home.html');
            break;
        }
        }  else {
            include('home.html'); 
        }
现在,当按下链接或提交表单时,我可以轻松调用新页面,即:

<a href="index.php?page=home">Home</a> <a href="index.php?page=contact_us">Contact Us</a> 
我需要它的原因是我的
index.php
使用
divs
作为格式,因此如果我不通过
index.php
请求页面,它们将显示在新的html中(即它没有我的导航栏等)

根据@HydraIO和其他人的评论,如何使用JQuery实现这一点

下面是一些代码:

lgoin.php:

<?php session_start(); ?>
<!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>
        <title>Login</title>
        <meta http-equiv="content-type"
        content="text/html; charset=iso-8859-1"
        />
        <!--
            //thanks http://decoraora.com/fototapete_115x175.php for the image http://decoraora.com/fototapete/images/664.jpg -->
        <style type="text/css">
        .table { 
            background: url("bg.jpg") no-repeat; 
            width: 600px;
            height: 250px;
        }
        </style>
    </head>

    <body>
        <?php           
            if (isset($_POST['formLogin'])) {
                    $un = $_POST['username'];
                    $pwd = $_POST['password'];
                    if($pwd!=''&&$un!='') {
                        if (md5($pwd)==='29ef52e7563626a96cea7f4b4085c124') {
                            $_SESSION['loggedin'] = true;
                            $_SESSION['login_error'] = 0;
                            $_SESSION['username'] = $un;
                            $_SESSION['password'] = $pwd;
                            //include('profile.php');
                            //header("Location: index.php/page=profile");
                        //header("Location: http://localhost/index.php?index.php?page=profile");

                        } else {
                            $_SESSION['login_error'] = 1;
                            echo 'this will dipslay in its own page';
                            //include('login.php');
                        }
                    }else {
                        $_SESSION['login_error'] = 2;
                            echo 'display in its own page';
                        //include('login.php');

        ?>
        <form action="login.php" method="post">
            <table bgcolor="white" align="center" border="1px" width="50%" style="height: 40%;">
                <tr>
                    <td colspan="2" align="center">Login for CC Chat</td>
                </tr>
                <tr>
                    <td>Username:</td>
                    <td>Password:</td>
                </tr>
                <tr>
                    <td><input type="text" name="username" maxlength="50"/></td>
                    <td><input type="password" name="password" maxlength="50"/></td>
                </tr>
                <tr>
                    <td><a href="index.php?page=contact_us">Forgot your password?</a></td>
                    <td><input type="submit" name="formLogin" value="Login"/></td>
                </tr>
                <?php 
                    if(isset($_SESSION['login_error'])) {
                        switch ($_SESSION['login_error']) {
                            case 1:
                                echo '<tr>';
                                echo '<td>';
                                echo '<font color="red">Password does not match</font>';
                                echo '</td>';
                                echo '</tr>';
                                $_SESSION['login_error']=0;
                            break;
                            case 2:
                                echo '<tr>';
                                echo '<td>';
                                echo '<font color="red">Password and/or Username cannot be empty</font>';
                                echo '</td>';
                                echo '</tr>';
                                $_SESSION['login_error']=0;
                            break;
                            default:
                            break;
                        }
                    }
                    ?>
                <tr>
                    <td colspan="2" align="center">&copy; CopyLeft David Kroukamp  11039662 2013 - 2015</td>
                </tr>
            </table>
        </form>
        <?php 
        }
        }else {
        ?>
        <form action="login.php" method="post">
            <table bgcolor="white" align="center" border="1px" width="50%" style="height: 40%;">
                <tr>
                    <td colspan="2" align="center">Login for CC Chat</td>
                </tr>
                <tr>
                    <td>Username:</td>
                    <td>Password:</td>
                </tr>
                <tr>
                    <td><input type="text" name="username" maxlength="50"/></td>
                    <td><input type="password" name="password" maxlength="50"/></td>
                </tr>
                <tr>
                    <td><a href="index.php?page=contact_us">Forgot your password?</a></td>
                    <td><input type="submit" name="formLogin" value="Login"/></td>
                </tr>
                <?php 
                    if(isset($_SESSION['login_error'])) {
                        switch ($_SESSION['login_error']) {
                            case 1:
                                echo '<tr>';
                                echo '<td>';
                                echo '<font color="red">Password does not match</font>';
                                echo '</td>';
                                echo '</tr>';
                                $_SESSION['login_error']=0;
                            break;
                            case 2:
                                echo '<tr>';
                                echo '<td>';
                                echo '<font color="red">Password and/or Username cannot be empty</font>';
                                echo '</td>';
                                echo '</tr>';
                                $_SESSION['login_error']=0;
                            break;
                            default:
                            break;
                        }
                    }
                    ?>
                <tr>
                    <td colspan="2" align="center">&copy; CopyLeft David Kroukamp  11039662 2013 - 2015</td>
                </tr>
            </table>
        </form>
        <?php
        }
        ?>
    </body>

</html>

登录
.表{
背景:url(“bg.jpg”)不重复;
宽度:600px;
高度:250px;
}
登录CC聊天
用户名:
密码:
&抄袭;版权所有David Kroukamp 11039662 2013-2015
登录CC聊天
用户名:
密码:
&抄袭;版权所有David Kroukamp 11039662 2013-2015
index.php:

<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>CC Chat</title>
        <meta 
        http-equiv="content-type" content="text/html; charset=iso-8859-1" 
        />
        <!-- 
        Thanks too http://stackoverflow.com/a/7851347/1133011 for the help
        on layout which acts more like frames but avoids them and using divs. As frames have 
        known draw backs see here http://stackoverflow.com/questions/4600648/frames-with-php we
        should thus rather use include in php
        !-->
        <style type="text/css" media="screen">
        /* Generic pane rules */
            body { margin: 0 }
            .row, .col { overflow: hidden; position: absolute; }
            .row { left: 0; right: 0; }
            .col { top: 0; bottom: 0; }
            .scroll-x { overflow-x: auto; }
            .scroll-y { overflow-y: auto; }

            .header.row { height: 75px; top: 0; background-color: #E5E5E5; }
            .menu.row { height: 75px; top: 75px; background-color: #EDEDED;  }
            .body.row { top: 150px; bottom: 50px; background-color: #F5F5F5; }
            .footer.row { height: 75px; bottom: 0; background-color: #EBEBEB; }

            A:link {text-decoration: none}
            A:visited {text-decoration: none}
            A:active {text-decoration: none}
            A:hover {font-size:24; font-weight:bold; color: red;}
        </style>
        <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    </head>
    <body>
        <div class="header row">
            <?php 
                include("header.html"); 
            ?>
        </div> 
        <div class="body row scroll-y">
            <?php
        if(isset($_GET['page'])) {
                        switch ($_GET['page']) {
                            case 'login':
                                include('login.php');
                            break;
                            case 'log_out':
                                $_SESSION['loggedin'] = false;
                                include('loggedout.html');
                            break;
                            case 'profile':
                                include('profile.php');
                            break;
                            case 'contact_us':
                                include('contact.html');
                            break;
                            default:
                                include('home.html');
                            break;
                        }
                }  else {
                    include('home.html'); 
                }
            ?>
        </div> 
        <div class="menu row">
            <?php 
                include("nav.php"); 
            ?>
        </div> 
        <div class="footer row">
            <?php 
                include("footer.php"); 
            ?>
        </div>
    </body>
</html>

抄送聊天
/*通用窗格规则*/
正文{页边距:0}
.row、.col{溢出:隐藏;位置:绝对;}
.行{左:0;右:0;}
.col{top:0;bottom:0;}
.scroll-x{overflow-x:auto;}
.scroll-y{overflow-y:auto;}
.header.row{高度:75px;顶部:0;背景色:#e5;}
.menu.row{高度:75px;顶部:75px;背景色:#EDEDED;}
.body.row{顶部:150px;底部:50px;背景色:#f5;}
.footer.row{高度:75px;底部:0;背景色:#ebebebeb;}
A:链接{文本装饰:无}
A:已访问{文本装饰:无}
A:活动{文本装饰:无}
A:悬停{字体大小:24;字体大小:粗体;颜色:红色;}
使用检查密码哈希的if语句中的JQuery尝试更新:

<?php session_start(); ?>
<!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>
        <title>Login</title>
        <meta http-equiv="content-type"
        content="text/html; charset=iso-8859-1"
        />
        <!--
            //thanks http://decoraora.com/fototapete_115x175.php for the image http://decoraora.com/fototapete/images/664.jpg -->
        <style type="text/css">
        .table { 
            background: url("bg.jpg") no-repeat; 
            width: 600px;
            height: 250px;
        }
        </style>    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

    </head>

    <body>
        <?php           
            if (isset($_POST['formLogin'])) {
                    $un = $_POST['username'];
                    $pwd = $_POST['password'];
                    if($pwd!=''&&$un!='') {
                        if (md5($pwd)==='29ef52e7563626a96cea7f4b4085c124') {
                            $_SESSION['loggedin'] = true;
                            $_SESSION['login_error'] = 0;
                            $_SESSION['username'] = $un;
                            $_SESSION['password'] = $pwd;
                            //include('profile.php');
                            //header("Location: index.php/page=profile");
                            //header("Location: http://localhost/index.php?index.php?page=profile");
                            //exit();
        echo "<script type='text/javascript'>";
        echo "$.get('index.php?page=profile', function(data) {
  $('.body.row').html(data);
  alert('Load was performed.');
});";  
echo "</script>";
                        } else {
                            $_SESSION['login_error'] = 1;
                            echo 'this will dipslay in its own page';
                            //include('login.php');
                        }
                    }else {
                        $_SESSION['login_error'] = 2;
                            echo 'display in its own page';
                        //include('login.php');

        ?>
        <form action="login.php" method="post">
            <table bgcolor="white" align="center" border="1px" width="50%" style="height: 40%;">
                <tr>
                    <td colspan="2" align="center">Login for CC Chat</td>
                </tr>
                <tr>
                    <td>Username:</td>
                    <td>Password:</td>
                </tr>
                <tr>
                    <td><input type="text" name="username" maxlength="50"/></td>
                    <td><input type="password" name="password" maxlength="50"/></td>
                </tr>
                <tr>
                    <td><a href="index.php?page=contact_us">Forgot your password?</a></td>
                    <td><input type="submit" name="formLogin" value="Login"/></td>
                </tr>
                <?php 
                    if(isset($_SESSION['login_error'])) {
                        switch ($_SESSION['login_error']) {
                            case 1:
                                echo '<tr>';
                                echo '<td>';
                                echo '<font color="red">Password does not match</font>';
                                echo '</td>';
                                echo '</tr>';
                                $_SESSION['login_error']=0;
                            break;
                            case 2:
                                echo '<tr>';
                                echo '<td>';
                                echo '<font color="red">Password and/or Username cannot be empty</font>';
                                echo '</td>';
                                echo '</tr>';
                                $_SESSION['login_error']=0;
                            break;
                            default:
                            break;
                        }
                    }
                    ?>
                <tr>
                    <td colspan="2" align="center">&copy; CopyLeft David Kroukamp  11039662 2013 - 2015</td>
                </tr>
            </table>
        </form>
        <?php 
        }
        }else {
        ?>
        <form action="login.php" method="post">
            <table bgcolor="white" align="center" border="1px" width="50%" style="height: 40%;">
                <tr>
                    <td colspan="2" align="center">Login for CC Chat</td>
                </tr>
                <tr>
                    <td>Username:</td>
                    <td>Password:</td>
                </tr>
                <tr>
                    <td><input type="text" name="username" maxlength="50"/></td>
                    <td><input type="password" name="password" maxlength="50"/></td>
                </tr>
                <tr>
                    <td><a href="index.php?page=contact_us">Forgot your password?</a></td>
                    <td><input type="submit" name="formLogin" value="Login"/></td>
                </tr>
                <?php 
                    if(isset($_SESSION['login_error'])) {
                        switch ($_SESSION['login_error']) {
                            case 1:
                                echo '<tr>';
                                echo '<td>';
                                echo '<font color="red">Password does not match</font>';
                                echo '</td>';
                                echo '</tr>';
                                $_SESSION['login_error']=0;
                            break;
                            case 2:
                                echo '<tr>';
                                echo '<td>';
                                echo '<font color="red">Password and/or Username cannot be empty</font>';
                                echo '</td>';
                                echo '</tr>';
                                $_SESSION['login_error']=0;
                            break;
                            default:
                            break;
                        }
                    }
                    ?>
                <tr>
                    <td colspan="2" align="center">&copy; CopyLeft David Kroukamp  11039662 2013 - 2015</td>
                </tr>
            </table>
        </form>
        <?php
        }
        ?>
    </body>

</html>

登录
.表{
背景:url(“bg.jpg”)不重复;
宽度:600px;
高度:250px;
}
登录CC聊天
用户名:
密码:
&抄袭;版权所有David Kroukamp 11039662 2013-2015
登录CC聊天
用户名:
密码:
&抄袭;版权所有David Kroukamp 11039662 2013-2015

我看到了警报,但像以前一样被重定向到一个空白html(甚至比以前还要多,至少表单被重新加载了)

听起来您可能想首先评估索引页面中的所有数据,然后通过将内部php设置为相同的索引页面,并将get查询更新为您想要的任何内容来执行页面重定向

header("Location: http://www.example.com/index.php?page=profile");
exit();

在执行重定向之前,请确保不使用echo或任何其他方式输出任何html。如果您的脚本之前大量使用echo,则可以查看echo。

PHP是服务器端语言,不是动态的。您希望使用javascript(在我的示例中为jQuery)

$\u GET=;
如果($\u GET['val']==某个值){
$.get(index.php?getvar=getval{
完成:函数(){
$('#div').val(“您的输出”);//*
}
});
}

*这可以是您喜欢的任何代码,如果您选择

php是服务器端的,那么您可以用整个php文件替换div,因此无法执行您试图执行的操作。请尝试jquery.ajax()您想使用jQuery进行此操作。@HydraIO+1感谢更新的问题…我如何通过jQuery>Load使用HTTP GET请求从服务器加载数据来实现这一点..GET()将立即发送GET请求。感谢查看这个带有注释头的更新代码示例…这给了我错误,但我认为这是因为回音thing@DavidKroukamp:检查输出缓冲如果在执行重定向之前使用了大量回显,请查看my login.php代码和注释标题在if语句中…它给出错误警告:无法修改头信息-头已由发送(输出从C:\Program Files(x86)\Apache Software Foundation\Apache2.2\htdocs\login.php:22开始)@DavidKroukamp:在第1行之后关闭php并输出html。在这之前打开输出缓冲。然后在脚本末尾显示缓冲区中的内容。@DavidKroukamp:要理解吗
header("Location: http://www.example.com/index.php?page=profile");
exit();
$_GET = <?php echo json_encode($_GET); ?>;
if($_GET['val'] == some_value){
  $.get(index.php?getvar=getval, {
    complete: function(){
      $('#div').val("YOUR OUTPUT"); // *
    }
  });
}