Reply
help with $_GET and URLS
Old 11-05-2009, 04:07 AM help with $_GET and URLS
Junior Talker

Posts: 2
Name: mike
Trades: 0
help please,

I am a newbie to php, although im not new to programming and can work out most things. Either I cant see the what maybe staring me in the face or im missing something.

Im trying to get variables from an url, and thats fine like this:
$cpage=$_REQUEST['cpage'];
$l1page = $_REQUEST['l1page'];
$l2page = $_REQUEST['l2page'];

for an url like this:
localhost/index.php?cpage=ViewNews.php&l1page=LeftMenu.php&l 2page=LeftMenu2.php&npage=1

but if the url has no info in it like
localhost/index.php

then im getting lots of these warnings
Notice: Undefined index: npage in C:\wamp\www\ViewNews.php on line 14

I want to know how to check if the data in the url exists, and fix the code

I know i can turn off these warnings, but i'd rather fix the code.

nb, i have tried this:
if (empty($cpage))
{
$cpage='ViewNews.php';
}

but it doesn't seem to work, what i want it to do is if the page is the base web url or localhost, redirect to the page above, else read what variables are there and direct to that page.

My problem is that every link needs to be treated like this as my index page is set to load a header, menus and the main page as includes so i really need to get this working correctly

*update

I tried this:
global $cpage;
$cpage='';
if (!isset($cpage))
{
$cpage=$_REQUEST['cpage'];
}
if (empty($cpage))
{
$cpage='ViewNews.php';
}

although it fixes the define error, i cant read in the new link variables

Last edited by mickle026; 11-05-2009 at 04:23 AM..
mickle026 is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 11-05-2009, 04:13 AM Re: help with $_GET and URLS
chrishirst's Avatar
Super Moderator

Posts: 22,260
Location: Blackpool. UK
Trades: 0
RTM......
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Growing old is mandatory - Growing up is optional
Code Samples | People Counting System | Bits & Bobs
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-05-2009, 10:46 AM Re: help with $_GET and URLS
Extreme Talker

Posts: 172
Trades: 0
Try:

$cpage=$_GET['cpage'];
__________________
Daniel, Helpdesk Leader
Hosting24.com Web Hosting - First class web hosting services.
Reseller Hosting - Provide unlimited disk space and bandwidth!
Hosting24 is offline
Reply With Quote
View Public Profile
 
Old 11-05-2009, 01:29 PM Re: help with $_GET and URLS
Skilled Talker

Posts: 61
Name: John
Trades: 0
PHP Code:
$cpage = !empty($_GET['cpage']) ? $_GET['cpage'] : 'ViewNews.php' 
Envision_frodo is offline
Reply With Quote
View Public Profile
 
Old 11-06-2009, 03:03 AM Re: help with $_GET and URLS
Junior Talker

Posts: 2
Name: mike
Trades: 0
Quote:
Originally Posted by Envision_frodo View Post
PHP Code:
$cpage = !empty($_GET['cpage']) ? $_GET['cpage'] : 'ViewNews.php' 
Thanks you guys for your help, the code above does what i need - many thanks
mickle026 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to help with $_GET and URLS
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.13294 seconds with 13 queries