weird error

Hello, i have made a script that ask for the user email address.

when an user gives his email address , he gets loged in to my system using this link:

$target     = "http://$uamip".':'.$uamport.$dir."?username=$username&password=$enc_pwd&userurl=$redir";
					header("Location: $target");

Open in new window


here is the code with no style (this code work )

<?php
include('db.php');
	$challenge = $_REQUEST['challenge'];
	$userurl   = $_REQUEST['userurl'];
	$res	   = $_REQUEST['res'];
	$qs        = $_SERVER["QUERY_STRING"];

    $uamip     = $_REQUEST['uamip'];
    $uamport   = $_REQUEST['uamport'];
    $mac_address   = $_REQUEST['mac'];


    //--There is a bug that keeps the logout in a loop if userurl is http%3a%2f%2f1.0.0.0 ---/
    //--We need to remove this and replace it with something we want
    if (preg_match("/1\.0\.0\.0/i", $userurl)) {
        $default_site = 'google.com';
        $pattern = "/1\.0\.0\.0/i";
        $userurl = preg_replace($pattern, $default_site, $userurl);
    }
    //---------------------------------------------------------

	if($res == 'success'){

		header("Location: $userurl");
		print("\n</html>");
	}

	if($res == 'failed'){

		header("Location: /hotspot/fail.php?".$qs);
		print("\n</html>");

	}

   
    if($res == 'notyet'){

		// Validate Form and login User
		if(isset($_POST['submit'])){
			$email = trim($_POST['email']);
			$agree = $_POST['agree'];
			$validate_email = filter_var($email, FILTER_VALIDATE_EMAIL);
			// var_dump($agree);
			// exit();
			if($validate_email !== false && $agree == 1){
				$access_date = date('Y-m-d H:i:s');
				$q = mysql_query("INSERT INTO promo_users VALUES (NULL, '$email', '$mac_address', '$access_date')");
				if($q){
					$uamsecret  = 'greatsecret';
					$dir        = '/logon';
					$userurl    = 'http://www.mywebsite.com';
					$redir      = urlencode($userurl);

					// Just use a user created for guest usage, e.g username: guest, password: guest
					$username   = 'guest';
					$password   = 'guest';
					$enc_pwd    = return_new_pwd($password,$challenge,$uamsecret);
					$target     = "http://$uamip".':'.$uamport.$dir."?username=$username&password=$enc_pwd&userurl=$redir";
					header("Location: $target");
					print("\n</html>");
				} else {
					header("Location: index.php?".$qs);
					print("\n</html>");
				}
			} else {
				header("Location: index.php?".$qs);
				print("\n</html>");
			}
		}
	
    }
    //Function to do the encryption thing of the password
    function return_new_pwd($pwd,$challenge,$uamsecret){
            $hex_chal   = pack('H32', $challenge);                  //Hex the challenge
            $newchal    = pack('H*', md5($hex_chal.$uamsecret));    //Add it to with $uamsecret (shared between chilli an this script)
            $response   = md5("\0" . $pwd . $newchal);              //md5 the lot
            $newpwd     = pack('a32', $pwd);                //pack again
            $password   = implode ('', unpack('H32', ($newpwd ^ $newchal))); //unpack again
            return $password;
    }

?>
<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Demo Promo</title>
</head>
<body>

<form action="" method="post">
	<h4>Enter your email address below to redeem your free internet access!</h4>
	<p>
		<label>Email Address:</label>
		<input type="text" name="email">
	<p>
	<p>
		<input type="checkbox" name="agree" value="1">
		<label>I have read and I agree with your <a href="terms.php">terms and conditions</a>, take me to the internet!</label>
	</p>
	<p>
		<input type="submit" name="submit" value="Redeem Access">
	</p>

</form>

</body>
</html>

Open in new window



but when i add some style to the page the , it does not work , so i dont get this link
$target     = "http://$uamip".':'.$uamport.$dir."?username=$username&password=$enc_pwd&userurl=$redir";
					header("Location: $target");

Open in new window



this code does not work:

this is the index and i have used include ("login.html");
to see the <form action="" method="post"> ...  part of it in an other page called login.html

<?php
include_once('include/webzone.php');
include_once('include/presentation/header.php');

$email = $_GET['email'];
$force_connect = 1;

?>

<div class="container">
	<br>
	
	<?php
	$f1 = new Fb_ypbox();
	$user_data = $f1->getUserData();
	$token = $f1->getAccessToken();
	
	$url = 'https://graph.facebook.com/'.$user_data['id'].'/likes?access_token='.$token;
	$data = $f1->getDataFromUrl($url);
	$data = json_decode($data, true);
	$data = $data['data'];
	$liked = 0;
	for($i=0; $i<count($data); $i++) {
		if($GLOBALS['like_page_id']==$data[$i]['id']) $liked=1;
	}
	
	if(count($user_data)>0) {
		$force_connect=0;
		$users = get_users(array('fb_user_id'=>$user_data['id']));
		if(count($users)>0) {
			if($users[0]['fb_token_expires']!=0 && time()>$users[0]['fb_token_expires']) {
				$force_connect=1;
			}
		}
		else {
			$force_connect=1;
		}
	}
	
	if($email!='') $force_connect=0;
	
	echo '<div id="locked_content">';
	
		if($force_connect==1) {
			include ("login.html");
			
		}
		else {
			
			if(($liked && count($user_data)>0) || $email!='') {
				
				if($email!='') {
					$user = get_users(array('email'=>$email));
					if(count($user)==0) {
						$m1 = new MySqlTable();
						$sql = 'INSERT INTO '.$GLOBALS['db_table']['users'].' (fb_email, created) VALUES ("'.$email.'", "'.date('Y-m-d H:i:s').'")';
						$m1->executeQuery($sql);
					}
				}
				
				//After Facebook like
				$result = get_settings();
	for($i=0; $i<count($result); $i++) {
		$settings[$result[$i]['meta_key']] = $result[$i]['meta_value'];
	}
	echo '<div style="margin-top:40px;">'.$settings['locked_content'].'</div>';
	$challenge = $_REQUEST['challenge'];
	$userurl   = $_REQUEST['userurl'];
	$res	   = $_REQUEST['res'];
	$qs        = $_SERVER["QUERY_STRING"];

    $uamip     = $_REQUEST['uamip'];
    $uamport   = $_REQUEST['uamport'];
    $mac_address   = $_REQUEST['mac'];


    //--There is a bug that keeps the logout in a loop if userurl is http%3a%2f%2f1.0.0.0 ---/
    //--We need to remove this and replace it with something we want
    if (preg_match("/1\.0\.0\.0/i", $userurl)) {
        $default_site = 'google.com';
        $pattern = "/1\.0\.0\.0/i";
        $userurl = preg_replace($pattern, $default_site, $userurl);
    }
    //---------------------------------------------------------

	if($res == 'success'){

		header("Location: $userurl");
		exit();
		//print("\n</html>");
	}

	if($res == 'failed'){

		header("Location: /hotspot/fail.php?".$qs);
		exit();
		//print("\n</html>");

	}

   
    if($res == 'notyet'){

					$uamsecret  = 'greatsecret';
					$dir        = '/logon';
					$userurl    = 'http://www.computersv.be';
					$redir      = urlencode($userurl);

					// Just use a user created for guest usage, e.g username: guest, password: guest
					$username   = 'guest';
					$password   = 'guest';
					$enc_pwd    = return_new_pwd($password,$challenge,$uamsecret);
					$target     = "http://$uamip".':'.$uamport.$dir."?username=$username&password=$enc_pwd&userurl=$redir";
					header("Location: $target");
					exit();
					//print("\n</html>");
					
				} else {
					header("Location: http://www.computersv.be");
					exit();
					//print("\n</html>");
				}
				
			}
			else {
				include ("like.php");
				
				
			}
		}
	
	echo '</div>';
	 function return_new_pwd($pwd,$challenge,$uamsecret){
            $hex_chal   = pack('H32', $challenge);                  //Hex the challenge
            $newchal    = pack('H*', md5($hex_chal.$uamsecret));    //Add it to with $uamsecret (shared between chilli an this script)
            $response   = md5("\0" . $pwd . $newchal);              //md5 the lot
            $newpwd     = pack('a32', $pwd);                //pack again
            $password   = implode ('', unpack('H32', ($newpwd ^ $newchal))); //unpack again
            return $password;
    }
	?>

</div>

<?php
include_once('include/presentation/footer.php');
?>

Open in new window


login.html:

<!DOCTYPE html>
<!--[if IE 8]>			<html class="ie ie8"> <![endif]-->
<!--[if IE 9]>			<html class="ie ie9"> <![endif]-->
<!--[if gt IE 9]><!-->	<html> <!--<![endif]-->
	<head>

		<!-- Basic -->
		<meta charset="utf-8">
		<title>YiFi.be</title>
		<meta name="keywords" content="HTML5 Template" />
		<meta name="description" content="Porto - Responsive HTML5 Template">
		<meta name="author" content="Crivos.com">

		<!-- Mobile Metas -->
		<meta name="viewport" content="width=device-width, initial-scale=1.0">

		<!-- Web Fonts  -->
		<link href="http://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800|Shadows+Into+Light" rel="stylesheet" type="text/css">

		<!-- Libs CSS -->
		<link rel="stylesheet" href="css/bootstrap.css">
		<link rel="stylesheet" href="css/fonts/font-awesome/css/font-awesome.css">
		<link rel="stylesheet" href="vendor/flexslider/flexslider.css" media="screen" />
		<link rel="stylesheet" href="vendor/magnific-popup/magnific-popup.css" media="screen" />

		<!-- Theme CSS -->
		<link rel="stylesheet" href="css/theme.css">
		<link rel="stylesheet" href="css/theme-elements.css">
		<link rel="stylesheet" href="css/theme-animate.css">

		<!-- Current Page Styles -->
		<link rel="stylesheet" href="vendor/revolution-slider/css/settings.css" media="screen" />
		<link rel="stylesheet" href="vendor/revolution-slider/css/captions.css" media="screen" />
		<link rel="stylesheet" href="vendor/circle-flip-slideshow/css/component.css" media="screen" />

		<!-- Custom CSS -->
		<link rel="stylesheet" href="css/custom.css">

		<!-- Skin CSS -->
		<link rel="stylesheet" href="css/skins/blue.css">

		<!-- Responsive CSS -->
		<link rel="stylesheet" href="css/bootstrap-responsive.css" />
		<link rel="stylesheet" href="css/theme-responsive.css" />

		<!-- Favicons -->
		<link rel="shortcut icon" href="img/favicon.ico">
		<link rel="apple-touch-icon" href="img/apple-touch-icon.png">
		<link rel="apple-touch-icon" sizes="72x72" href="img/apple-touch-icon-72x72.png">
		<link rel="apple-touch-icon" sizes="114x114" href="img/apple-touch-icon-114x114.png">
		<link rel="apple-touch-icon" sizes="144x144" href="img/apple-touch-icon-144x144.png">

		<!-- Head Libs -->
		<script src="vendor/modernizr.js"></script>

		

	</head>
    
	<body class="boxed">
    <div class="body">
	<img src="img/top.gif" alt=""><!-- Libs -->
		<div class="row center">
        <br/><br/><br/>
			<p class="featured lead">
				Verbind met Facebook en krijg toegang tot WiFi
			</p><a href="./account/fb_connect.php">
<img src="img/facebook.png" href="./account/fb_connect.php" alt="">
</a>
           
            
							
			</div>
            <div class="row left">
        <br/><br/><br/><br/> <br/>
			<p class="featured lead">
				<a href="geenfb.php/">Ik heb geen facebook</strong></a>
			</p>
           
            
							<form action="" method="post">
	<h4>Enter your email address below to redeem your free internet access!</h4>
	<p>
		<label>Email Address:</label>
		<input type="text" name="email">
	<p>
	<p>
		<input type="checkbox" name="agree" value="1">
		<label>I have read and I agree with your <a href="terms.php">terms and conditions</a>, take me to the internet!</label>
	</p>
	<p>
		<input type="submit" name="submit" value="Redeem Access">
	</p>

</form>
			</div>

      <br/> <br/> <br/> <br/>

</div>
	</body>
</html>

Open in new window


What i really whant is this, when a user gives his mail and hit submit ,

i want it to go to this url to login in to my system:

$target     = "http://$uamip".':'.$uamport.$dir."?username=$username&password=$enc_pwd&userurl=$redir";
					header("Location: $target");

Open in new window

Babak01Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
Is there a question here?  Or is it just "something you want?"  If you want to learn how PHP client authentication works, this article may be helpful.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_2391-PHP-login-logout-and-easy-access-control.html

If there is a different question, please post back and we will be glad to help. ~Ray
0
Babak01Author Commented:
yes my question is why does it not work in the seconde code ?
0
Sharon SethCommented:
What is the error you see?
0
Ray PaseurCommented:
... why does it not work in the seconde code ?
This is probably best approached step-by-step.  Start with the first example that works satisfactorily, then begin to add in the components of the "styled" script one at a time.  The first example has 80 lines of code, not counting the HTML form; the styled example has 147 lines.  The answer is probably somewhere in the 67 lines that are added to the styled example.

Some tools to help you debug: Var_dump() can be used to print out the values of variables in your script.  It will explore complex variables (objects and arrays) recursively.  Trigger_error() can be used to visualize failures of function calls, etc.  Error_reporting() can be set to the highest level.  Most of the PHP functions return values, and testing these values for success or failure is an absolute requirement for successful programming.

From the look of the code, I would expect it has been copied from something published somewhere else on the internet, and that's usually a bad way to learn programming.  Some more structured learning resources are identified in this article.  I would especially recommend the Welling/Thompson book.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html

And since you probably need to refactor this anyway in order to get it to work, you might consider "future proofing" a little bit.  PHP is doing away with MySQL support.  This article explains why and what you must do to keep your scripts running.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.