Newbie Question
am 20.08.2007 01:42:49 von GalatorgHow do I have my whole site on one page of PHP and to get to the pages
would be something like
domain.com/index.php?page1
domain.com/index.php?page2
How do I have my whole site on one page of PHP and to get to the pages
would be something like
domain.com/index.php?page1
domain.com/index.php?page2
>How do I have my whole site on one page of PHP and to get to the pages
>would be something like
>
>domain.com/index.php?page1
>domain.com/index.php?page2
You can get hold of the part of the query after the ? with:
$_SERVER['QUERY_STRING']
but that also includes GET or POST variables, if any, which you'd need
to remove. It might be easier to make your URL of the form:
domain.com/index.php?p=page1
and retrieve it with $_REQUEST['p'] .
After you get the value into a variable, you can use something like:
switch($_REQUEST['p']) {
case 'page1': /* code for page 1 goes here */
break;
case 'page2': /* code for page2 goes here */
break;
default: /* code for unexpected page goes here */
break;
}
On Aug 19, 5:05 pm, gordonb.66...@burditt.org (Gordon Burditt) wrote:
> >How do I have my whole site on one page of PHP and to get to the pages
> >would be something like
>
> >domain.com/index.php?page1
> >domain.com/index.php?page2
>
> You can get hold of the part of the query after the ? with:
>
> $_SERVER['QUERY_STRING']
> but that also includes GET or POST variables, if any, which you'd need
> to remove. It might be easier to make your URL of the form:
>
> domain.com/index.php?p=page1
>
> and retrieve it with $_REQUEST['p'] .
>
> After you get the value into a variable, you can use something like:
>
> switch($_REQUEST['p']) {
> case 'page1': /* code for page 1 goes here */
> break;
> case 'page2': /* code for page2 goes here */
> break;
> default: /* code for unexpected page goes here */
> break;
> }
It doesn't seem to be working.
On Aug 19, 5:05 pm, gordonb.66...@burditt.org (Gordon Burditt) wrote:
> >How do I have my whole site on one page of PHP and to get to the pages
> >would be something like
>
> >domain.com/index.php?page1
> >domain.com/index.php?page2
>
> You can get hold of the part of the query after the ? with:
>
> $_SERVER['QUERY_STRING']
> but that also includes GET or POST variables, if any, which you'd need
> to remove. It might be easier to make your URL of the form:
>
> domain.com/index.php?p=page1
>
> and retrieve it with $_REQUEST['p'] .
>
> After you get the value into a variable, you can use something like:
>
> switch($_REQUEST['p']) {
> case 'page1': /* code for page 1 goes here */
> break;
> case 'page2': /* code for page2 goes here */
> break;
> default: /* code for unexpected page goes here */
> break;
> }
Here is the code I tried:
switch($_REQUEST['p']) {
case 'page1': echo "page 1"
break;
case 'page2': echo "page 2"
break;
default: echo "index"
break;
}
?>
I access the code by typing in domain.com/index.php?p=page1
It then returns:
Parse error: syntax error, unexpected T_BREAK, expecting ',' or ';' on
line 4
On Aug 19, 8:04 pm, Galat...@gmail.com wrote:
> On Aug 19, 5:05 pm, gordonb.66...@burditt.org (Gordon Burditt) wrote:
>
>
>
> > >How do I have my whole site on one page of PHP and to get to the pages
> > >would be something like
>
> > >domain.com/index.php?page1
> > >domain.com/index.php?page2
>
> > You can get hold of the part of the query after the ? with:
>
> > $_SERVER['QUERY_STRING']
> > but that also includes GET or POST variables, if any, which you'd need
> > to remove. It might be easier to make your URL of the form:
>
> > domain.com/index.php?p=page1
>
> > and retrieve it with $_REQUEST['p'] .
>
> > After you get the value into a variable, you can use something like:
>
> > switch($_REQUEST['p']) {
> > case 'page1': /* code for page 1 goes here */
> > break;
> > case 'page2': /* code for page2 goes here */
> > break;
> > default: /* code for unexpected page goes here */
> > break;
> > }
>
> Here is the code I tried:
>
>
> switch($_REQUEST['p']) {
> case 'page1': echo "page 1"
> break;
> case 'page2': echo "page 2"
> break;
> default: echo "index"
> break;
> }
>
> ?>
>
> I access the code by typing in domain.com/index.php?p=page1
>
> It then returns:
>
> Parse error: syntax error, unexpected T_BREAK, expecting ',' or ';' on
> line 4
It could be because you are missing ; at the end of your echo
statements.
<1187571873.248314.29230@i38g2000prf.googlegroups.com>, says...
> Here is the code I tried:
>
>
> switch($_REQUEST['p']) {
> case 'page1': echo "page 1"
> break;
> case 'page2': echo "page 2"
> break;
> default: echo "index"
> break;
> }
>
> ?>
>
> I access the code by typing in domain.com/index.php?p=page1
>
> It then returns:
>
> Parse error: syntax error, unexpected T_BREAK, expecting ',' or ';' on
> line 4
Semicolons are needed at the end of each of your echo statements.
GM
Galatorg@gmail.com wrote:
> On Aug 19, 5:05 pm, gordonb.66...@burditt.org (Gordon Burditt) wrote:
>>> How do I have my whole site on one page of PHP and to get to the pages
>>> would be something like
>>> domain.com/index.php?page1
>>> domain.com/index.php?page2
>> You can get hold of the part of the query after the ? with:
>>
>> $_SERVER['QUERY_STRING']
>> but that also includes GET or POST variables, if any, which you'd need
>> to remove. It might be easier to make your URL of the form:
>>
>> domain.com/index.php?p=page1
>>
>> and retrieve it with $_REQUEST['p'] .
>>
>> After you get the value into a variable, you can use something like:
>>
>> switch($_REQUEST['p']) {
>> case 'page1': /* code for page 1 goes here */
>> break;
>> case 'page2': /* code for page2 goes here */
>> break;
>> default: /* code for unexpected page goes here */
>> break;
>> }
>
>
> It doesn't seem to be working.
>
Did you actually put your code in there?
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Never mind I just got everything working.
if ($_GET['p'] == "1") {
echo "Page 1";
}
elseif ($_GET['page'] == "2") {
echo "Page 2";
}
else {
echo "Index";
}
?>