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 Link to comment https://forums.phpfreaks.com/topic/186881-if-else-different-page/ 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 } ?> Link to comment https://forums.phpfreaks.com/topic/186881-if-else-different-page/#findComment-986917 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; } Link to comment https://forums.phpfreaks.com/topic/186881-if-else-different-page/#findComment-986961 Share on other sites More sharing options...
adamriley Posted January 2, 2010 Author Share Posted January 2, 2010 Thanks you both for you reply Link to comment https://forums.phpfreaks.com/topic/186881-if-else-different-page/#findComment-987092 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> } ?> Link to comment https://forums.phpfreaks.com/topic/186881-if-else-different-page/#findComment-987159 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 Link to comment https://forums.phpfreaks.com/topic/186881-if-else-different-page/#findComment-987161 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 ?> Link to comment https://forums.phpfreaks.com/topic/186881-if-else-different-page/#findComment-987194 Share on other sites More sharing options...
adamriley Posted January 2, 2010 Author Share Posted January 2, 2010 Thanks very much works fine Link to comment https://forums.phpfreaks.com/topic/186881-if-else-different-page/#findComment-987231 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.