paulman888888 Posted July 7, 2008 Share Posted July 7, 2008 I remember seeing this on this site before but i coulnt remember the link or what to search. The problem was that someone wanted to use the get command to find pages. eg index.php?where=contact and the php script is abit like this <?php $sws=$_GET['where'] //the problem is here //i dont know how to right it include 'pages/' $sws '.php' ?> Hope you understand the question thankyou paul Quote Link to comment https://forums.phpfreaks.com/topic/113599-solved-i-remember-but-where/ Share on other sites More sharing options...
ag3nt42 Posted July 7, 2008 Share Posted July 7, 2008 i don't really understand your question.. but to use GET you need to first use a form (usually) <form action='page.php' method='get'> <input type='text' value='' name='Something' /> <input type='submit' name='submit' value='Submit Me!' /> </form> then on the (page.php) <?php $Something=$_GET['Something']; ?> the http url would look similar to this http://something.com/page.php?Something=TheValue hmm.. to get pages?? maybe like this? <?php if($_GET['Something']==Contact) { require('contact.php'); //Would include the page and show the data on contact.php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/113599-solved-i-remember-but-where/#findComment-583695 Share on other sites More sharing options...
LemonInflux Posted July 7, 2008 Share Posted July 7, 2008 Student from the UK, doing Unit 2 on the atain course? Haha, great fun (not). Quote Link to comment https://forums.phpfreaks.com/topic/113599-solved-i-remember-but-where/#findComment-583697 Share on other sites More sharing options...
anon_login_001 Posted July 7, 2008 Share Posted July 7, 2008 Are you trying to make sure the file exists before loading/including it? Or making sure the user has the right to access a particular page? Quote Link to comment https://forums.phpfreaks.com/topic/113599-solved-i-remember-but-where/#findComment-583700 Share on other sites More sharing options...
mbeals Posted July 7, 2008 Share Posted July 7, 2008 I remember seeing this on this site before but i coulnt remember the link or what to search. The problem was that someone wanted to use the get command to find pages. eg index.php?where=contact and the php script is abit like this <?php $sws=$_GET['where'] //the problem is here //i dont know how to right it include 'pages/' $sws '.php' ?> Hope you understand the question thankyou paul include 'pages/' $sws '.php' isn't valid code and may be your issue. try this: <?php $sws=$_GET['where']; include "pages/$sws.php"; ?> This will take any name in the GET 'where' variable and attempt to find and load that page (plus the php extension) from the pages dir. Notice...you need to end all statements with a semicolon (. Also, when building strings you have to concatenate them properly. Enclosing a string with double quotes (" ") tells php to parse the contents and operate on special chars. So variables will be dereferenced and special characters like \n will be turned into their proper form. Single quotes tell php to treat it literally. $test = "hello world"; echo "$test"; // this will echo "hello world" to the browser echo '$test'; // this will echo "$test" to the browser You can concatenate with periods as well ie: include "pages/$sws.php"; ##can be written as include 'pages/'.$sws.'.php'; The "pages/" and ".php" strings are taken as literals and are tacked onto the value of $sws Quote Link to comment https://forums.phpfreaks.com/topic/113599-solved-i-remember-but-where/#findComment-583864 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.