Jump to content

Undefined Index


HDFilmMaker2112

Recommended Posts

okay, I'll have to live with it then.

 

It's because I'm using Mod_Rewrite on a few on my URLs.

 

For example domain.com/index.php?signup is accessible  as domain.com/signup, but if you type index.php?signup in the address bar it still works. So I'm catching stuff after the "?" as $key and then comparing it to see if $key is equal to the values that I've rewritten with mod_rewrite, and if it is redirecting to the rewritten url.

 

It's included in function.php which I call on some pages that don't have a ? in the URL so it throws a notice on those pages apparently.

Link to comment
Share on other sites

FYI, The query string (everything after the ?) is available in $_SERVER['QUERY_STRING'].  No need to try and parse it out of the request uri.

 

 

True story. Listen to this man.

 

I tried using this but it sent the browser into a indefinite loop and eventually ended in a browser alert saying something along the lines of "This page is trying to redirect in a way that will never load.".  It would work fine for URLs that have the question mark in them, but I'd end up with the alert on pages that didn't.

 

So index.php?signup would redirect to /signup, but /signup would never actually load because it lacked the question mark. Or atleast that's what it seemed like was going.

 

This is what I was using:

if(isset($_SERVER['QUERY_STRING'])){
$key=$_SERVER['QUERY_STRING'];
}

 

Using the method you posted I have no issues what so ever.

Link to comment
Share on other sites

FYI, The query string (everything after the ?) is available in $_SERVER['QUERY_STRING'].  No need to try and parse it out of the request uri.

 

 

True story. Listen to this man.

 

I tried using this but it sent the browser into a indefinite loop and eventually ended in a browser alert saying something along the lines of "This page is trying to redirect in a way that will never load.".  It would work fine for URLs that have the question mark in them, but I'd end up with the alert on pages that didn't.

 

So index.php?signup would redirect to /signup, but /signup would never actually load because it lacked the question mark. Or atleast that's what it seemed like was going.

 

This is what I was using:

if(isset($_SERVER['QUERY_STRING'])){
$key=$_SERVER['QUERY_STRING'];
}

 

Using the method you posted I have no issues what so ever.

 

$_SERVER['QUERY_STRING'] is always "set", but it will be an empty string if no query string is present. So, you need to check if it is empty and not set.

if (!empty($_SERVER['QUERY_STRING'])) {
$key = $_SERVER['QUERY_STRING'];
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.