?
Solved

If URL contains a parameter and variable, do not include PHP

Posted on 2009-12-28
5
Medium Priority
?
361 Views
Last Modified: 2012-05-08
I have a PHP require at the head of my page:
<?php
require_once('shared/includes/DetectJavascript.php');
?>
What I need now is to check in the URL for the parameter/variable 'cookies=yes'.  If this exists in the URL I need to skip the require and proceed with the code that follows.  

For example, when the DetectJavascript.php' code detects javascript/cookies, it takes the user to 'login.php?cookies=yes'.  The login.php code contains the include, so the user get stuck on a loop over and over so I need some PHP that will skip the include if that parameter/variable is present in the URL.

Any ideas?
0
Comment
Question by:AGDeacon
4 Comments
 
LVL 5

Accepted Solution

by:
andoneknight earned 2000 total points
ID: 26134992
if ( $_GET['cookies'] != 'yes' ) {
    require_once('shared/includes/DetectJavascript.php');
}
0
 
LVL 1

Expert Comment

by:shaziashaikh
ID: 26136100
<?php
if ((isset($_REQUEST['cookies'])) && ($_REQUEST['cookies'] == "yes"))
{
      // variable 'cookies' present in the URL
}
else
{
      // variable 'cookies' not present in the URL
}
?>`
0
 
LVL 1

Expert Comment

by:AnithaRajesh
ID: 26137323
Hi,

For any parameter you are passing in the query string you can fetch those variables in $_GET/$_REQUEST method.

In your code as you have specified that the variable is cookies,  you can check as

if(!($_GET['cookies'])){
 require_once('shared/includes/DetectJavascript.php');
}


0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 26138778
@AGDeacon, Premium Service Member:  I think you have pretty good answers here from others, but I wanted to share this little script with you.  It teaches you how to visualize your URL arguments.  

You get URL arguments when the action method = "get"  and you get post arguments when the action method = "post"  - in the latter case, you want to look at $_POST instead of $_GET.

Both of $_GET and $_POST are "superglobal" - that means they are present in every namespace, inside classes and functions, etc.  And, somewhat amazingly, they are not immutable - you can change them (although I would advise against this - treat them as read-only).
<?php // RAY_dump_GPC.php
error_reporting(E_ALL);
echo "<pre>\n"; // EASY READABILITY


// VISUALISE THE SUPERGLOBAL ARRAYS THAT CONTAIN EXTERNAL DATA


// THE URL FIELDS ARE IN $_GET
echo "\n_GET ";
var_dump($_GET);

// THE POST FIELDS ARE IN $_POST
echo "\n_POST ";
var_dump($_POST);

// THE COOKIE FIELDS ARE (GUESS WHERE?!)
echo "\n_COOKIE ";
var_dump($_COOKIE);

Open in new window

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

616 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question