Jump to content

[SOLVED] I remember but where...


paulman888888

Recommended Posts

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

Link to comment
Share on other sites

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
}

?>

Link to comment
Share on other sites

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

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.