Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

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
 
 
Register now for full access!
Old 11-05-2009, 04:13 AM Re: help with $_GET and URLS
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,515
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
RTM......
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-05-2009, 10:46 AM Re: help with $_GET and URLS
Ultra Talker

Posts: 339
Trades: 0
Try:

$cpage=$_GET['cpage'];
__________________
Daniel, Helpdesk Leader

Please login or register to view this content. Registration is FREE
- First class web hosting services.

Please login or register to view this content. Registration is FREE
- 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: 80
Name: John
Location: Sacramento
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.14896 seconds with 12 queries