简体   繁体   中英

How to get a url parameter

I'm having problems getting a URL parameter.

The error is the following:

Notice: Undefined index: link in C:\\xampp\\htdocs+Gesol\\modulos\\login\\form.php on line 3

This is how the URL looks: http://localhost:82/+Gesol/login/form/ingreso?link=/+Gesol/outdoors-servicios/form/8780

session code:

if ($gl_to == "ver"):   //VERIFICA QUE EXISTA SESSION

  if (!isset($_SESSION['id']) or !isset($_SESSION['empresa']) or !isset($_SESSION['user']) or !isset($_SESSION['nombre']) or !isset($_SESSION['email']) or !isset($_SESSION['gesol'])):

         if (isset($Gl_config_cms_url)){
            $link = $_SERVER['REQUEST_URI'];
            header("Location: ".$Gl_config_cms_url."login/form/ingreso?link=$link"); 
            exit(); 
         }else{
            header("Location: ./login/form/ingreso");
            exit(); 
         }

  endif;

endif;

Login form code:

<?php

$link = $_GET['link'];

echo $link;
exit;

session_start();
require_once ("../../../global/-gl-abre-conexion-gesol.php");
require_once ("../../global/gl-funciones.php");

$Gl_accion="INQ"; require_once("../../modulos/configuracion/XML-config.php");

#--- Revisa si esta entrando desde https solo si el sitio tiene https activo en la url
if(substr($Gl_config_cms_url,0,5)=="https"):

    if (!isset($_SERVER['HTTPS'])):
        header("Location: ".$Gl_config_cms_url."login/form/ingreso"); 
    endif;

endif;


#--- Valida Usuarios
$Gd_error = "";
if (!empty($_POST))
{
    if (isset($_POST['user']) and isset($_POST['pass']))
        {

        require("SQL-login.php");
        if ($Gl_existe_user=="N")
            {

                $Gd_error =  "Nombre de usuario y/o contraseña no válido. <br/> ¿<a href='./login/lost/password'>Has olvidado tu contraseña</a>? "; 

            }else{

                $Gl_usuario = $Gd_user_id;
                require("../../modulos/usuarios/SQL-tb_gesol_acceso.php");                      
                if ($Gl_existe_miplusAcceso=="S")#---Valida si el usuario tiene acceso a pantallas
                {
                    $gl_to = "crear";
                    require("../../global/gl-session.php");
                    header("Location: ".$Gl_config_cms_url."panel/home/"); 
                    exit();             
                }else{
                    $Gd_error =  "Usuario sin privilegios para ingresar al CMS, favor contacte a su proveedor.";
                }

            }

        }else{

            $Gd_error =  "Ingrese Usuario y contraseña para ingresar al sistema.";

        }

}else{

    $gl_to = "revisa";
    require_once("../../global/gl-session.php");

}

#--- Maneja fondos segun hora del día
$Gd_hora = date("H"); $Gd_fondo = "dia";
if ($Gd_hora>=6)
    $Gd_fondo = "dia";

if ($Gd_hora>=13)
    $Gd_fondo = "tarde";

if ($Gd_hora>=20 or ($Gd_hora>=1 and $Gd_hora<=5))
    $Gd_fondo = "noche";        
#--- 
?>
<!DOCTYPE html>
<html lang="es" class="lockscreen lockscreen-<?=$Gd_fondo?>">
<head>

    <meta charset="UTF-8">
    <title>GESOL | CRM</title>
    <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
    <meta name="description" content="Sistema de Gestión de Solicitudes GESOL">
    <meta name="author" content="Tecnología Aplicada y Comunicaciones TAYCO.cl">
    <meta name="Generator" content="GESOL" />
    <meta name="robots" content="noindex">
    <meta name="googlebot" content="noindex">

    <link href="<?=$Gl_config_cms_url?>css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
    <link href="<?=$Gl_config_cms_url?>css/Gesol.css" rel="stylesheet" type="text/css" />
    <link href="<?=$Gl_config_cms_url?>css/images/favicon.ico" rel="shortcut icon">

    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
    <![endif]-->

</head>
<body>  

     <div class="form-box" id="login-box">
        <div class="header"><img src="<?=$Gl_config_cms_url?>css/images/logo-gesol-login.png"></div>
        <form action="./ingreso" method="post">
            <div class="body bg-gray">

                <div class="form-group">
                    <input type="text" name="user" class="form-control" placeholder="Usuario" required="" />
                </div>
                <div class="form-group">
                    <input type="password" name="pass" class="form-control" placeholder="Contraseña" required=""/>
                </div>   
                <!--       
                <div class="form-group">
                    <input type="checkbox" name="remember_me"/> Recordar
                </div>
                -->

            </div>

            <div class="footer">                                    
                <button type="submit" class="btn bg-light-blue btn-block">Ingresar</button>                      
                <p class="text-center"><a href="<?=$Gl_config_cms_url?>login/lost/password">Olvide mi Contraseña</a></p> 
            </div>
        </form>     

        <?php if ($Gd_error!=""):?>
            <br/>
            <div class="callout callout-danger">
                <h4>MIPLUS ERROR</h4>
                <p><?=$Gd_error?></p>
            </div>
        <?php endif;?> 

        <div class="margin text-center copyright">
            <span>MADE WITH <i class="fa fa-heart"></i> IN CHILE BY <b>TAYCO.cl</b></span>
        </div>
    </div>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
    <script src="<?=$Gl_config_cms_url?>js/bootstrap.min.js" type="text/javascript"></script>   
    <?php if ($Gd_error!=""):?>
    <script src="https://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>     
    <script type="text/javascript">
        $(function() {
            $(".form-box").effect("shake");
        });
    </script>   
    <?php endif;?>

</body>
</html>
<?php
require_once ("../../../global/-gl-cierra-conexion-gesol.php"); ?>

As you can see, i'm trying to get the "?link=$link" who contains a url that i need. ( /+Gesol/outdoors-servicios/form/8780 )

Quick answer:

<form action="./ingreso" method="post">

you cannot get link by $_GET you may get it like $_POST['link'] (if you set it inside the form by a <input> object.

Alternate answer

if you want to really get it with $_GET variable then you should write it like:

<form action="./ingreso?link=http://whatyouwanttowrite..." method="post">

You did not send a POST variable link from the form. you may set it manually like

<input type="hidden" name="link" value="https://www.google.com">

then you may get it with $_POST

Alternate solution use $_REQUEST which combines $_GET and $_POST variables.

$link = $_REQUEST['link'];

Supressing error: you may put a @ to supress the error. like $link = @$_GET['link'];

Your login form is shown first? If so, $_GET['link'] on line 3 of form isn't available. Surround it in an isset condition

Because it does not find your $_GET['link'] but you can not see this message after your form request. Below code helps you. As Shane said.

if(isset($_GET['link']))
{
    something here...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM