473,386 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

PHP Variable Troubles - $_GET

5
Hi,

I am building my new website and I want to confine the menu to one file, but make it so that the user can see what page he/she is on. For this I came up with the following code:
Expand|Select|Wrap|Line Numbers
  1. <?php $page = $_GET['page']; ?>
  2. <?php $page1 = 'page1'; $page2 = 'page2'; $page3 = 'page3'; $page4 = 'page4';?>
Where $pagenumber = 'inputvalue' in $_GET from the URL.
The menu is then below, as:
Expand|Select|Wrap|Line Numbers
  1. <?php if ($page == $page1) {echo "<div id=\"menuon\"><a href=\"/index.php?page=$page1\">Homepage</a></div>";} else {echo "<div id=\"menuoff\"><a href=\"/index.php?page=$page1\">Homepage</a></div>";} ?>
  2. <?php if ($page == $page2) {echo "<div id=\"menuon\"><a href=\"/index.php?page=$page2\">Some Page</a></div>";} else {echo "<div id=\"menuoff\"><a href=\"/index.php?page=$page2\">Some Page</a></div>";} ?>
This works absolutely fine until I go to the top-level domain where there is no "$_GET['page']" input for the script to pick up on. I need it to recognise a non-input as the homepage, so that I don't have to redirect it to " /index.php?page=page1 ".
I have tried a few wacky and wonderful ways of doing this but none have been successful. Does anybody have any solutions or suggestions?

Many thanks,
Mar 28 '11 #1
2 1362
I hope the following bunch of code will help you...

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if(!isset($_GET['page'])){
  3.  $page='page1';
  4. }
  5. else{
  6. $page=$_GET['page'];
  7. }
  8. ?>
Mar 29 '11 #2
Cobain
5
Hi abhishekmiet,

Thanks for that, works a treat! I think that PHP is great, but it is sooo annoying when you forget things!

Thanks again!
Mar 29 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Dave B. | last post by:
Hey gang, I am probably missing something basic. I have a bunch of arrays in one of my ASP scripts, and I need to construct the reference to the variable through some string contatenations. ...
0
by: Donal | last post by:
I have the following: <xsl:variable name="position"><xsl:value-of select="position()"/></xsl:variable> <xsl:attribute name='style'><xsl:value-of...
7
by: Andy Fish | last post by:
consider the following fragment of xsl: <xsl:variable name="v1"><xsl:if test="false()"/></xsl:variable> <xsl:variable name="v2"></xsl:variable> <xsl:value-of select="boolean($v1)"/>...
0
by: Jane | last post by:
Hi, I have a template column in a datagrid, its heder is set like this... <asp:TemplateColumn HeaderText="Mon" HeaderStyle-HorizontalAlign="center"> But I want the header to say "Mon 4 Oct"...
8
by: Fernando Barsoba | last post by:
Hi, I decided to start a new topic about my memory allocation question. One of the answers was that variable length arrays are possible using C99. I found this topic that also mentions it. ...
5
by: shethsheetal | last post by:
I am having some problem with the below mentioned trigger. CREATE TRIGGER D.TBA AFTER UPDATE OF TBAA.CIC ON TBAA REFERENCING NEW AS NEW_ROW FOR EACH ROW MODE DB2SQL BEGIN ATOMIC DECLARE RS...
6
by: Pawan | last post by:
Hi, Can anyone please suggest me on this. I am using var variable to get a string.Its working fine if string is of simple type. But giving error after entering 'Enter' or 'special...
1
TheMan1
by: TheMan1 | last post by:
Hi guys, I've done something stupid. I accidently deleted some of the environment variables on my XP laptop. Now it has stuffed up my installation of OracleDevSuite. So if possible, could you guys...
1
by: Kev | last post by:
Hello All, I am attempting to use the variable "AccAllow " which is populated by opening a recordset. I am using AccAllowed to refer to a control on the active form (the Switchboard) but I am...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.