<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Login with email address + curl don&#x27;t work in local]]></title><description><![CDATA[<p dir="auto">Hi pfSense users!</p>
<p dir="auto">I'm new to pfSense and want to customize the captive portal. I want it to do a simple thing: users on the LAN are redirected to the captive portal which ask them for their email address. If the address is valid, they are logged-in, else a message warn them of invalid email address.</p>
<p dir="auto">I created login.php, a simple form which auto-post $PORTAL_REDIRURL$ and  $PORTAL_ACTION$ (they are not replaced in another php-only page).</p>
<p dir="auto">It seems that I cannot execute php script more than ~200 bytes long in login.php: the start of them is interpreted, and after a certain point, script content is outputed as-is in the html source. It's why it splitted the code into 2 php files:</p>
<p dir="auto"><strong>login.php</strong></p>
<p dir="auto">I want the second file, <strong>captiveportal-login.php</strong> to ask for the email address, and connect as a defined user (ie: guest). I think the better way to do this is that the script itself check email address and post to $PORTAL_ACTION$.</p>
<p dir="auto">Here is the simplified code of <strong>captiveportal-login.php</strong>:</p>
<pre><code>
/**
 * http_build_query don't exists in PHP4
 */
if (!function_exists('http_build_query')) {
	[... simulatre http_build_query ...]
}

// Page not called by login.php, redirect to login.php
if (!isset($_POST["portal_action"]) || !isset($_POST["portal_redirurl"])) {
	header('Location: login.php');
	die();
}

// Redirection from login.php, get portal addresses
$portal_action = $_POST["portal_action"];
$portal_redirurl = $_POST["portal_redirurl"];

// Checks if email address have been post, else show login form
if (!isset($_POST["email"]))
{
	showLoginForm($portal_action, $portal_redirurl);
	die();
}

// Got a mail address
$email = trim($_POST["email"]);

// If email if invalid, shows a failure message
if (!validEmail($email))
{
	showLoginForm($portal_action, $portal_redirurl, 'The mail you entered is invalid!');
	die();
}

// Got a valid email, post user and password to the portal login form
//*****************
echo "server respond: " . Post($portal_action , "auth_user=guest&amp;auth_pass=passw0rd&amp;redirurl=$portal_redirurl&amp;accept=Continue");
//******************

/**
Validate an email address.
Provide email address (raw input)
Returns true if the email address has the email 
address format and the domain exists.
*/
function validEmail($email)
{
    [... check email and set result in $isValid]
   return $isValid;
}

/**
 * Shows the login form
 */
function showLoginForm($portal_action, $portal_redirurl, $message = "")
{

echo '

## Login

		Please enter your email address to log-in to the portal.

		**' .  $message . '**

&lt;form method="POST" action="captiveportal-login.php"&gt;
			Email address: 

		&lt;/form&gt;

	';
}

/**
 * POST content to a page
 */
function Post($url, $post)
{
	$ch = curl_init($url);
	curl_setopt ($ch, CURLOPT_POST, 1);
	curl_setopt ($ch, CURLOPT_POSTFIELDS,  $post);
	$result =  curl_exec ($ch);
	curl_close ($ch);

	return $result;
}
?&gt;

</code></pre>
<p dir="auto">My problem come from the Post function: I tried curl, fopen, readfile, exec(curl)… It can post to and get the response from an external page, but when I try getting $PORTAL_ACTION$ (for me <strong>http://1.2.3.4:8000</strong>) I get an error saying that the destination is unreacheable or a timeout, or simply nothing (instead exec('ls') shows me a result).</p>
<p dir="auto">Do you think this code is the best way to do email-authentification?<br />
Do you know why curl sucks so much in local?</p>
<p dir="auto">Regards,<br />
thegigistouch</p>
]]></description><link>https://forum.netgate.com/topic/18692/login-with-email-address-curl-don-t-work-in-local</link><generator>RSS for Node</generator><lastBuildDate>Thu, 08 Oct 2026 01:20:59 GMT</lastBuildDate><atom:link href="https://forum.netgate.com/topic/18692.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 20 Oct 2009 06:59:40 GMT</pubDate><ttl>60</ttl></channel></rss>