duanchui1251 2015-06-16 10:42
浏览 68
已采纳

重定向到div元素php

Hi I want that the user becomes redirected to the main div after the login. Now the problem is that it wont work. The PHP mysql connection work well but the user wont become redirected to the main div. How can the user redirected after successful login to the main div?

the error message in my browser:

ERR_TOO_MANY_REDIRECTS

login.php

<?php
if(isset($_COOKIE['username'])){
    $cookie = $_COOKIE['username'];
    header('Location: http://' . $_SERVER['HTTP_HOST'] . '/local/mainn.php');
}
else{
    $message = array();
    if (!empty($_POST)) {
        if (
            empty($_POST['f']['username'])

            ) {
                $message['error'] = 'Es wurden nicht alle Felder ausgefüllt.';
            } 
            $mysqli = @new mysqli('localhost', 'root', '', '');
                if ($mysqli->connect_error) {
                    $message['error'] = 'Datenbankverbindung fehlgeschlagen: ' . $mysqli->connect_error;
                }
                $query = sprintf(
                    "INSERT INTO user (username)
                    SELECT * FROM (SELECT '%s') as new_user
                    WHERE NOT EXISTS (
                        SELECT username FROM user WHERE username = '%s'
                    ) LIMIT 1;",
                    $mysqli->real_escape_string($_POST['f']['username']),

                    $mysqli->real_escape_string($_POST['f']['username'])

                );


                $mysqli->query($query);
                if ($mysqli->affected_rows == 1) {
                    $message['success'] = 'Neuer Benutzer (' . htmlspecialchars($_POST['f']['username']) . ') wurde angelegt, <a href="login.php">weiter zur Anmeldung</a>.';
                    header('Location: http://' . $_SERVER['HTTP_HOST'] . '/local/mainn.php');
                    $id = $mysqli->insert_id;
                } else {

                }
                $t = time() + 60 * 60 * 60 * 24 * 1000;
                setcookie("username", $_POST['f']['username'], $t);
                setcookie("userid", $id , $t);
                // cookie setzen
                $mysqli->close();
            }
    }
    ?>
    <html>
    <head>
        <meta charset="UTF-8" /> 
        <title>
            HTML Document Structure
        </title>
        <link rel="stylesheet" type="text/css" href="style.css" />

        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" />
        <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
        <script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>

        <!-- Einstellungen zur Defintion als WebApp -->
        <meta name="apple-mobile-web-app-capable" content="yes" />
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

    </head>
    <body>

    <div id="wrapper1" name="wrapper1">

        <form name="login-form" class="login-form" action="./login.php" method="post">

            <div class="header1">
            </div>

            <div class="content1">
            <label for="username"></label>
            <input name="f[username]" type="text" class="input username" placeholder="Username" id="username"
            />

            </div>

            <div class="footer">
            <input type="submit" name="submit" value="Login" class="button" data-theme="b"/>
            </div>

        </form>

    </div>
    <div class="gradient"></div>

    <script type="text/javascript">

    if(navigator.geolocation) {

        navigator.geolocation.getCurrentPosition(
                                        success_handler, 
                                        error_handler, 
                                        {enableHighAccuracy:true});

        function success_handler(position) {
            /* Get the location data */
            latitude = position.coords.latitude;
            longitude = position.coords.longitude;
            accuracy = position.coords.accuracy;

            document.cookie = 'latitude='+latitude+'; ';  
    document.cookie = 'longitude='+longitude+'; ';


        }

        function error_handler() {
        output.innerHTML = "Unable to retrieve your location";
      };

    }





    </script>
    </body>
    </html>

mainn.php:

<body> 
<?php
include("login.php");
?>

<!-- main Seite -->
<div data-role="page" id="main">
<?php
include("usercoords.php");
?>

<div data-role="header" data-theme="b" data-position="fixed" data-tap-toggle="false"> 

        <h1>localy</h1>
        <a href="#popupLogin" data-rel="popup" data-position-to="window" data-transition="pop">range</a>
<div data-role="popup" id="popupLogin" data-theme="b" class="ui-corner-all">
    <form name="login-form" class="login-form" action="./range.php" method="post" style="padding:10px 20px;">
        <div class="content">
        <label for="slider-fill">Select range:</label>
<input type="range" name="slider-fill" id="slider-fill" value="5" min="0" max="100" step="1" data-highlight="true">
        </div>
        <div class="footer">
        <input type="submit" name="submit" value="create" class="button" data-theme="b"/>

        </div>  
    </form>
</div>
    </div>

    <div data-role="content">

    </div><!-- div content -->


    <div data-role="footer" data-id="footernav" data-tap-toggle="false" data-position="fixed" data-theme="b">
        <div data-role="navbar" data-theme="b">
            <ul>
                <li><a href="#own posts" data-icon="menue" data-transition="fade">own posts</a></li>                
                <li><a href="#main" data-icon="anfahrt" data-transition="fade" class="ui-btn-active">main</a></li>
                <li><a href="#create post" data-icon="kontakt" data-transition="fade">create post</a></li>
            </ul>
        </div><!-- /navbar -->       
    </div><!-- /footer -->            
</div><!-- /page -->
  • 写回答

1条回答 默认 最新

  • doukezi4606 2015-06-16 12:01
    关注

    I deleted

    <?php
    include("login.php");
    ?>
    

    and launch the application with login.php.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。