[SOLUTION] What's $PORTAL_ACTION$ ? Need help with custom PHP page.



  • I'm having trouble creating a custom portal page that includes some validation:
    The validation works, but when the code continues by setting the header to $PORTAL_ACTION$, I'm redirected to http://<captiveportal>:8000/$, and then http://<captiveportal>:8000/captiveportal-p.php?redirurl= .

    I don't understand how $PORTAL_ACTION$ and $PORTAL_REDIRURL$ work.  I'm also new to PHP.

    Here's what I have.  I'd appreciate any and all corrections (getting it to work or just cleaning up any bad or unnecessary code). Thanks in advance!

    index.html to redirec to custom p.php

    
    		Redirecting . . .
    
    

    custom p.php

    	$message = ""; // set default error message to empty
    	$redirurl = $_GET['redirurl']; // get redirurl from URL
    
    	// if form submitted, validate
        if ($_POST['submitted'] == 1)
    	{
    		$pattern = '/.*@.*\..*/';
    		$email = $_POST['email'];
    		// if valid, continue
    		if (preg_match($pattern, $_POST['email']) > 0)
    		{
                header("location: $PORTAL_ACTION$");
            }
    		// if invalid, set error message to be displayed
            $message = "E-mail address must be valid!";
    	}
    ?>
    
    ## ACCEPTABLE USE POLICY
    
    		<iframe src="captiveportal-aup.html" style="width:90%;height:65%;margin-bottom:20px;"></iframe>
    		$message";?>
    
    <form method="post" action="<?echo $_SERVER['PHP_SELF'] . " ?redirurl=" . $redirurl;?>">
    			Please enter your e-mail address: 
    
    ### By clicking 'Continue' you agree to the Acceptable Use Policy.
    
    		</form>
    
    

    (NOTE: the code is incomplete; I realize I'm not actually doing anything with the e-mail address as of yet.)</captiveportal></captiveportal>



  • With some help from these two posts I've manged a solution:
    http://forum.pfsense.org/index.php/topic,5796.0.html (auto posting the form)
    http://forum.pfsense.org/index.php/topic,5368.0.html (passing action & redirurl to custom .php page)

    I'd still appreciate any corrections or suggestions.  Thanks!

    index.html:

    
    		Redirecting . . .
    
    

    p.php:```

    $message = ""; // set default error message to empty
    $portal_redirurl = $_GET['portal_redirurl']; // get portal_redirurl from URL
    $portal_action = $_GET['portal_action']; // get portal_action from URL
    
    // if form submitted, validate
    

    if ($_POST['submitted'] == 1)
    {
    $email = $_POST['email']; // get submitted e-mail address
    $pattern = '/.@...*/'; // used to "validate" submitted e-mail address

    	// if valid, process and auto-submit portal form
    	if (preg_match($pattern, $_POST['email']) > 0)
    	{
    		// use e-mail here . . .
    
    		// build auto-submitting for to allow user thru captive portal
    		echo "
    
    		";
    		exit; // prevents latter code from displaying
    

    }
    // if email is invalid, set error message to be displayed
            $message = "E-mail address must be valid!

    ";
    }
    ?>

    ACCEPTABLE USE POLICY

    	<iframe src="captiveportal-aup.html" style="width:90%;height:65%;margin-bottom:20px;"></iframe>
    	$message";?>
    

    <form method="post" action="<?echo $_SERVER['PHP_SELF'] . " ?portal_action=" . $portal_action . " &portal_redirurl=" . $portal_redirurl;?>">
    Please enter your e-mail address:

    By clicking 'Continue' you agree to the Acceptable Use Policy.

    	</form>
    

Locked