[Pro] PHP, cURL and Cookies

Typing the following URL into the browser address bar…

http://hartford.macusa.net/fmi/iwp/cgi?-db=Install_Info.fp7&-startsession

…displays Login page:

http://hartford.macusa.net/fmi/iwp/res/iwp_auth.html

Examining imp_auth.html in Safari’s Console reveals the following JavaScript:

<script type="text/javascript" language="JavaScript1.4">
<!--
	function setCookie(cookieName,value)
	{
			var today=new Date();
			today.setDate(today.getDate()+ 1);
			document.cookie=cookieName+ "=" +escape(value)+ ";expires="+today;
	}

	function getCookie(name)
	{
		var start = document.cookie.indexOf( name + "=" );
		if (start == -1) return null;
		var nameLength = start + name.length + 1;
		var end = document.cookie.indexOf( ';', nameLength );
		if (end == -1) end = document.cookie.length;
		return unescape(document.cookie.substring( nameLength, end ));
	}

	function checkCookie(){
		setCookie('check','check');
		testCookie = getCookie('check');
		
		if(testCookie == null){
			return false;
		}else{
			document.cookie = 'check' + '=' +';expires=Thu, 01-Jan-1970 00:00:01 GMT';
			return true;
		}
	}
			
	function getSid()
	{
		var url = window.top.location.href;
		var result = "";
		if ( url != null )
		{
			var sid = null;
			var index = null;
			if(checkCookie() == true){
				index = url.indexOf( "JSESSIONID=" );
			}else{
				index = url.indexOf( ";jsessionid=" );
			}
			if ( index != -1 )
			{
				var end = url.indexOf ( "&", index );
				if ( end != -1 )
				{
					result = url.substring ( index, end );
				}
				else
				{
					result = url.substr ( index );
				}
			}
		}
		return result;
	}

	var sid = getSid();
	if ( sid.length > 0 ){
		document.write ( '<script type="text/javascript" language="JavaScript1.4" src="/fmi/iwp/cgi' + sid+ '?-authinfo' + '"><' + '/script>' );
	}else{
		document.write ( '<script type="text/javascript" language="JavaScript1.4" src="/fmi/iwp/cgi?-authinfo' + '"><' + '/script>' );
	}
		

-->
</script>
<script type="text/javascript" language="JavaScript1.4" src="/fmi/iwp/cgi?-getstrings"></script>
<script type="text/javascript" language="JavaScript1.4">
		<!--
			function disableFields()
			{
				var acct = document.getElementById( "accnt" );
				var pass = document.getElementById( "pass" );
				acct.disabled = true;
				pass.disabled = true;
			}

			function enableFields()
			{
				var acct = document.getElementById( "accnt" );
				var pass = document.getElementById( "pass" );
				acct.disabled = false;
				pass.disabled = false;
			}

			function setup()
			{
				var ai = window.authinfo;
				var name = document.getElementById( "thingy" );
				var guest = document.getElementById( "guest-radio" );
				var account = document.getElementById( "acct-radio" );
				var login = document.getElementById( "login" );
				var cancel = document.getElementById( "cancel" );
				login.setAttribute( "value", iwp.strings.auth_btn_login );
				cancel.setAttribute( "value", iwp.strings.stat_btn_cancel );
				document.title = iwp.strings.home_ttl_iwp;
				if ( ai != null && name != null )
				{
					var txt;
					var sid = getSid();
					var form = document.getElementById( "form-elt" );
					if ( ai.realm.substring( 0, 9 ) == "FileMaker" )
					{
						txt = document.createTextNode( iwp.strings.auth_lbl_openfms );
						var type = document.getElementById( "type" );
						if ( sid.length > 0 )
							form.action = "/fmi/iwp/cgi" +sid+ "?-authserver";
						else
							form.action = "/fmi/iwp/cgi?-authserver";
						type.name = "-authserver";
						cancel.style.visibility = "hidden";
					}
					else
					{
						if ( sid.length > 0 )
							form.action = "/fmi/iwp/cgi" + sid + "?-authdb";
						txt = document.createTextNode( iwp.strings.auth_lbl_opendb + ai.realm.substring( 9 ) + iwp.strings.auth_lbl_with );
					}
					name.appendChild( txt );
					if ( ai.guest == "no" )
					{
						account.checked = true;
						guest.disabled = true;
					}
					if ( ai.retrycount > 0 )
					{
						if ( ai.retrycount >= 4 && ai.dbpath != null )
						{
							window.location = "/fmi/iwp/cgi?-home&reset";
						}
						var msg = document.getElementById( "msg" );
						msg.removeChild( msg.lastChild );
						var txt;
						if ( ai.realm.substring( 0, 9 ) == "FileMaker" )
							txt = document.createTextNode( iwp.strings.auth_err_server );
						else
							txt = document.createTextNode( iwp.strings.auth_err_incorrect );
						msg.appendChild( txt );
					}
					if ( ai.dbpath != null )
					{
						var hidden = document.getElementById( "dbpath" );
						hidden.value = ai.dbpath;
					}
				}
				document.getElementById( "accnt" ).focus();
				var obj = document.getElementById( "iwpTopBox" );
				var txt = document.createTextNode( iwp.strings.home_ttl_banner );
				obj.appendChild( txt );
			}
			if ( window.authinfo == null )
			{
				window.location = "/fmi/iwp/cgi?-home";
			}
		-->
		</script>
<link href="/fmi/iwp/res/iwp_home.css" rel="stylesheet" type="text/css">
</head>

<body onload="setup()">

This would seem to indicate that I cannot achieve my aims in PHP alone. Would you agree?


dynamo mailing list
email@hidden
Update your subscriptions at: