adamriley Posted January 1, 2010 Share Posted January 1, 2010 Ok to start with there is a variable called "$username" what i want is to see if the variable is got the value of "ar" which would show a html page but if the username is anything else i would like to "header" the user to a different page using if and else statements Quote Link to comment Share on other sites More sharing options...
Kalland Posted January 2, 2010 Share Posted January 2, 2010 <?php if ($username == 'ar') { // some page } else { // some other page } ?> Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted January 2, 2010 Share Posted January 2, 2010 Something like this? if(preg_match("/ar/", $username)){ // your html page here }else{ header("Location: index.php"); exit; } Quote Link to comment Share on other sites More sharing options...
adamriley Posted January 2, 2010 Author Share Posted January 2, 2010 Thanks you both for you reply Quote Link to comment Share on other sites More sharing options...
adamriley Posted January 2, 2010 Author Share Posted January 2, 2010 im new to php and this does not work any reason why not The error i get is "[sat Jan 02 15:53:37 2010] [error] [client 127.0.0.1] PHP Parse error: syntax error, unexpected '<' in C:\\web\\htdocs\\test1.php on line 6" <?php require_once('common.php'); checkUser(); ?> <?php if ($_SESSION['userName'] == 'Adamriley'){ <html> <head> <title>adam lee riley</title> </head> <body> </body> </html> }else{ <html> <head> <title>Nathan warburton</title> </head> <body> </body> </html> } ?> Quote Link to comment Share on other sites More sharing options...
teamatomic Posted January 2, 2010 Share Posted January 2, 2010 learn what a heredoc is, then use it HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
DavidAM Posted January 2, 2010 Share Posted January 2, 2010 Actually, just close PHP, output the HTML, then open PHP again: <?php require_once('common.php'); checkUser(); ?> <?php if ($_SESSION['userName'] == 'Adamriley'){ /* CLOSE PHP HERE BECAUSE WE WANT TO OUTPUT HTML */ ?> <html> <head> <title>adam lee riley</title> </head> <body> </body> </html> <?php }else{ /* OPEN PHP FOR THE ELSE THEN CLOSE IT FOR HTML AGAIN */ ?> <html> <head> <title>Nathan warburton</title> </head> <body> </body> </html> <?php } // OPEN PHP AGAIN FOR THE CLOSING BRACE ?> Quote Link to comment Share on other sites More sharing options...
adamriley Posted January 2, 2010 Author Share Posted January 2, 2010 Thanks very much works fine Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.