473,663 Members | 2,743 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there a shortcut i'm missing?

$name=$_GET['name'];
if (!$name)
$name="value";

i can't figure out how to shorten this thing. Is there some kind of
operator i don't know about?

Mar 26 '07 #1
7 1362
Lo'oris wrote:
$name=$_GET['name'];
if (!$name)
$name="value";

i can't figure out how to shorten this thing. Is there some kind of
operator i don't know about?
$name = isset($_GET['name']) ? $_GET['name'] : null;

You should always test with isset() to see if a value passed to your
page is set or not. Otherwise you will get a notice if you have them
enabled.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Mar 26 '07 #2
Jerry Stuckle wrote:
Lo'oris wrote:
>$name=$_GET['name'];
if (!$name)
$name="value";

i can't figure out how to shorten this thing. Is there some kind of
operator i don't know about?

$name = isset($_GET['name']) ? $_GET['name'] : null;

You should always test with isset() to see if a value passed to your
page is set or not. Otherwise you will get a notice if you have them
enabled.
If setting multiple variables from $_GET, you can also try this:

$parameters=arr ay('name'=>"val ue",'example'=> "value1",'anoth er'=>"value2");
foreach ($parameters as $parameter=>$va lue)
{
$$parameter=$_G ET[$parameter]?$_GET['parameter:$val ue;
}

--
cb
Mar 26 '07 #3
Christoph Burschka wrote:
Jerry Stuckle wrote:
>Lo'oris wrote:
>>$name=$_GET['name'];
if (!$name)
$name="value";

i can't figure out how to shorten this thing. Is there some kind of
operator i don't know about?
$name = isset($_GET['name']) ? $_GET['name'] : null;

You should always test with isset() to see if a value passed to your
page is set or not. Otherwise you will get a notice if you have them
enabled.

If setting multiple variables from $_GET, you can also try this:

$parameters=arr ay('name'=>"val ue",'example'=> "value1",'anoth er'=>"value2");
foreach ($parameters as $parameter=>$va lue)
{
$$parameter=$_G ET[$parameter]?$_GET['parameter:$val ue;
}
Which is only slightly less dangerous than running with register_global s
on. Someone can come in and set any variable in your script by setting
it in the query string. And if you miss initializing a variable you've
got a huge potential security breach.

One reason register_global s is no longer enabled by default.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Mar 26 '07 #4
Jerry Stuckle wrote:
Christoph Burschka wrote:
>Jerry Stuckle wrote:
>>Lo'oris wrote:
$name=$_GE T['name'];
if (!$name)
$name="value";

i can't figure out how to shorten this thing. Is there some kind of
operator i don't know about?

$name = isset($_GET['name']) ? $_GET['name'] : null;

You should always test with isset() to see if a value passed to your
page is set or not. Otherwise you will get a notice if you have them
enabled.

If setting multiple variables from $_GET, you can also try this:

$parameters=ar ray('name'=>"va lue",'example'= >"value1",'anot her'=>"value2") ;

foreach ($parameters as $parameter=>$va lue)
{
$$parameter=$_G ET[$parameter]?$_GET['parameter:$val ue;
}

Which is only slightly less dangerous than running with register_global s
on. Someone can come in and set any variable in your script by setting
it in the query string. And if you miss initializing a variable you've
got a huge potential security breach.

One reason register_global s is no longer enabled by default.
Not really. It think it's a clever way to do it. Save you some coding time.

If you see, he only allows the variable in the parameter to be changed.

But then again, it's only my oppinion.

Hendri
Mar 27 '07 #5
Hendri Kurniawan wrote:
Jerry Stuckle wrote:
>Christoph Burschka wrote:
>>Jerry Stuckle wrote:
Lo'oris wrote:
$name=$_G ET['name'];
if (!$name)
$name="value";
>
i can't figure out how to shorten this thing. Is there some kind of
operator i don't know about?
>
$name = isset($_GET['name']) ? $_GET['name'] : null;

You should always test with isset() to see if a value passed to your
page is set or not. Otherwise you will get a notice if you have them
enabled.
If setting multiple variables from $_GET, you can also try this:

$parameters=a rray('name'=>"v alue",'example' =>"value1",'ano ther'=>"value2" );

foreach ($parameters as $parameter=>$va lue)
{
$$parameter=$_G ET[$parameter]?$_GET['parameter:$val ue;
}

Which is only slightly less dangerous than running with
register_globa ls on. Someone can come in and set any variable in your
script by setting it in the query string. And if you miss
initializing a variable you've got a huge potential security breach.

One reason register_global s is no longer enabled by default.

Not really. It think it's a clever way to do it. Save you some coding time.

If you see, he only allows the variable in the parameter to be changed.

But then again, it's only my oppinion.

Hendri
Not at all. I key in

http://www.example.com?admin=1

And now in your program $admin=1. And what if $admin is the variable
which indicates I'm an admin?

This effectively does exactly what register_global s does - just limits
it to the $_GET variables.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Mar 27 '07 #6
Jerry Stuckle wrote:
Hendri Kurniawan wrote:
>Jerry Stuckle wrote:
>>Christoph Burschka wrote:
Jerry Stuckle wrote:
Lo'oris wrote:
>$name=$_GE T['name'];
>if (!$name)
> $name="value";
>>
>i can't figure out how to shorten this thing. Is there some kind of
>operator i don't know about?
>>
$name = isset($_GET['name']) ? $_GET['name'] : null;
>
You should always test with isset() to see if a value passed to your
page is set or not. Otherwise you will get a notice if you have them
enabled.
>

If setting multiple variables from $_GET, you can also try this:

$parameters= array('name'=>" value",'example '=>"value1",'an other'=>"value2 ");

foreach ($parameters as $parameter=>$va lue)
{
$$parameter=$_G ET[$parameter]?$_GET['parameter:$val ue;
}
Which is only slightly less dangerous than running with
register_glob als on. Someone can come in and set any variable in
your script by setting it in the query string. And if you miss
initializin g a variable you've got a huge potential security breach.

One reason register_global s is no longer enabled by default.

Not really. It think it's a clever way to do it. Save you some coding
time.

If you see, he only allows the variable in the parameter to be changed.

But then again, it's only my oppinion.

Hendri

Not at all. I key in

http://www.example.com?admin=1

And now in your program $admin=1. And what if $admin is the variable
which indicates I'm an admin?

This effectively does exactly what register_global s does - just limits
it to the $_GET variables.
Well in order to do that the $parameters variable have to include admin
is it.

Hendri
Mar 27 '07 #7
Lo'oris wrote:
$name=$_GET['name'];
if (!$name)
$name="value";

i can't figure out how to shorten this thing. Is there some kind of
operator i don't know about?
The current PHP method is:

$name = $_GET['name'] ? $_GET['name'] : 'value';

It was proposed that PHP 6 should have a new function "ifsetor" which
would achieve the same thing using this syntax:

$name = ifsetor($_GET['name'], 'value');

However, this proposal was rejected in favour for making the middle part
of the current method optional, so you could write:

$name = $_GET['name'] ? : 'value';

However, if you want to use the above, you'll need to wait for PHP 6, and
your code will not be backwards-compatible with earlier versions of PHP.

Personally, I've written my own ifsetor() function, and just use that.

/**
* Implementation of proposed (but discarded) PHP6 built-in function.
*
* @param mixed $value Preferred value.
* @param mixed $fallback Fallback value.
* @return mixed isset($value) ? $value : $fallback
*/
function ifsetor ($value, $fallback)
{
if (isset($value))
return $value;
return $fallback;
}

I use this most often for loading settings. Assuming I have a bunch of
settings from a file stored in some array:

$mode = ifsetor($settin gs['mode'], 3); // default mode is 3

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
Mar 27 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
17155
by: Todd Peterson | last post by:
I'm encountering some wierd behavior with a <link> tag over an HTTPS connection, vs. an HTTP connection... In an ASP/HTML page on my website, I've add a <link rel="shortcut icon"...> in order to allow the users to add a shortcut (with icon) on their desktop, as well as seeing the icon in the URL. Our development server allows both HTTP and HTTPS connections, but the icon only appears to be available when requesting the page via HTTP???...
2
1787
by: Top Gun | last post by:
I am trying to get the output from a setup project to place an entry on the menu plus a shortcut on the option, but setting the property's in User's Desktop and User's Programs Meny to true doesn't seem to do the trick. Am I missing something?
1
2288
by: Tom | last post by:
I created an msi using the Setup Wizard, but don't seem to be able to create a shortcut to the applicaton on the desktop (or prompt for one) or the menu. Also, I would like to add an "uninstall" to this, but don't see that it allows for this? Am I missing something?
3
2708
by: Terry Bell | last post by:
I have some code that adds entries to the "Module Compiled" popup menu. Works fine in A97. You can open a module, right click, and the new entries are there for you to click. I converted it to A2000, and reapplied the new entries. But now when you open a module and right click (in A2K), the new entries are nowhere to be seen. If (while in the database window) you click on View, Toolbars, Customize, Toolbars tab, tick the Shortcut Menus...
1
1469
by: exitstageleft | last post by:
Hi. I am missing the ability to use 'CTRL-SHIFT-F' shortcut key to search files in visual studio. It shows no shortcut key combination on the file menu for Edit->Find & Replace->Find in Files. It's just blank. How do I assign '...Find in Files' with that shortcut key combination?? Others here at work have it while I do not. tia.
4
4408
by: I_AM_DON_AND_YOU? | last post by:
There is one more problem I am facing but didn't get the solution. In my Setup Program I am not been able to create 2 things (when the program is intalled on the client machine ) : (1) create shortcut to my program/utility (2) Entry in Windows' Start --> Program Menu. Actually in my VB.Net solution I have two projects (1) MYPROGRAM (2) MYPROGRAM_INSTALLER. MYPROGRAM is a "Windows Application". MYPROGRAM_INSTALLER is a "SetUp Wizard"...
1
1389
by: tombsy | last post by:
Hello guys, I am missing the right click/build shortcut menu in my Access 2000 code modules. I cant remember the fix, any help please ? many thanks
2
3235
by: variaas | last post by:
Hey guys, So I created a setup project for my new app, but I don't know how to add a shortcut to the exe on the desktop. For now, I've created a link to the "Primary Output" of the project, but for some reason the icon it shows is a stack of papers, not the icon I have setup for the exe. The workaround I have in place is to create a shortcut manually after installing the project. Am I missing something here?
4
1833
by: Steve | last post by:
Hi All I have a windows forms application written in VB.net 2005 which places a shortcut in All users desktop during installation, using MS setup and deployment Occasionally when a customer goes to launch the program the installation screen appears instead of the program starting The strange thing is, if they create a new shortcut to the program .exe
10
3542
by: Matthew Wells | last post by:
I'm trying to make a shortcut that will open an mdb in the same folder as the shortcut - regardless of where the file/shortcut may be. In other words, I want to be able to copy and paste the two files anywhere and have the shortcut always open the mdb that was copied with it without having to change the shortcut properties. If I only use the mdb name without any path, the shortcut tries to look in the folder where msaccess.exe is. I've...
0
8436
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8858
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8771
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8548
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7371
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4349
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2000
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1757
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.