I don't _GET it!

This is a discussion on "I don't _GET it!" within the PHP Forum section. This forum, and the thread "I don't _GET it! are both part of the Program Your Website category.



 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1  
Old Jan 18th, 2007, 05:24
Reputable Member
Join Date: Mar 2005
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Posts: 245
Thanks: 6
Thanked 0 Times in 0 Posts
I don't _GET it!

_GET is used to get a querystring value from the URL, right?

Does it not work for some reason if that URL is not generated via a form (with method=get)?

I have a link on a page like so:
Code: Select all
<a href="http://my_other.site/contact.php?ws=this.site">contact</a>
contact.php contains
Code: Select all
<?php
$thissite = $_REQUEST[’ws’];
print "thissite = '".$thissite."'";
but what gets printed is:

thissite = ''

What am I doing wrong?!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Jan 18th, 2007, 23:31
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: I don't _GET it!

But your not using $_GET, you are using $_REQUEST!!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Jan 19th, 2007, 07:09
Reputable Member
Join Date: Mar 2005
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Posts: 245
Thanks: 6
Thanked 0 Times in 0 Posts
Re: I don't _GET it!

I was using $_GET (same results) - when that didn't work I tried $_REQUEST. I posted the wrong code but my problem is the same either way - it just doesn't work!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Jan 19th, 2007, 14:40
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Re: I don't _GET it!

Quote:
Originally Posted by ukgeoff View Post
But your not using $_GET, you are using $_REQUEST!!!

$_REQUEST contains everything that's in $_GET, plus $_COOKIE and a couple of other super-globals, so it should work just as well ...

Suggestion, Donny: Try pointing your link at a PHP page containing <?php phpinfo(); ?>. That will let you look at all the various superglobal variables and give you a clue as to what is happening. (I've had a look but couldn't spot anything obviously wrong)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Jan 19th, 2007, 16:21
masonbarge's Avatar
Highly Reputable Member
Join Date: Jan 2006
Location: Atlanta GA
Posts: 631
Thanks: 0
Thanked 0 Times in 0 Posts
Re: I don't _GET it!

That quote syntax is downright Byzantine. It's the single quotes that are killing you. Just write

Code: Select all
$thissite=$_GET['ws'];
print "thissite = $thissite";
If that doesn't work, narrow the problem with a few random tests like
Code: Select all
if ($_GET['ws']) { print "<br />$_GET['ws']<br />;
}else{
print '<br />no variable<br />'; }
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Jan 19th, 2007, 18:56
Reputable Member
Join Date: Mar 2005
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Posts: 245
Thanks: 6
Thanked 0 Times in 0 Posts
Re: I don't _GET it!

I should probably point out that I'm not a complete idiot. (No sarcasm there - I know you guys deal with people of all knowledge/skill levels. Mine isn't terribly high, but it's not terribly low, either. ) I started with the logical, correct syntax, and when that didn't work, I tried tweaking the syntax in every way I could think of, including print statements to get a look at the variable values.
Quote:
Originally Posted by grahame View Post
$_REQUEST contains everything that's in $_GET, plus $_COOKIE and a couple of other super-globals, so it should work just as well
I knew that, but when $_GET didn't work, I gave $_REQUEST a try - just in case.
Quote:
Suggestion, Donny: Try pointing your link at a PHP page containing <?php phpinfo(); ?>. That will let you look at all the various superglobal variables and give you a clue as to what is happening.
Thanks, Grahame. I gave that a try, but my knowledge level doesn't extend to the point where I could effectively interpret much of what I saw there. If anyone wants to have a look, here's a link: http://stickpuppy.com/phpinfo.php?site=dhs57.com
Quote:
Originally Posted by masonbarge View Post
That quote syntax is downright Byzantine.It's the single quotes that are killing you. Just write

Code: Select all
$thissite=$_GET['ws'];
print "thissite = $thissite";
Initially, that's precisely what I had written. The Byzantine quote syntax (I got a good chuckle out of that! ) was just a means of trying to see what was in $_GET['ws'] - similar to your

Code: Select all
if ($_GET['ws']) { print "<br />$_GET['ws']<br />;
}else{
print '<br />no variable<br />'; }
Incidentally - I tried it your way (the if staement above), and I got
Quote:
parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
(pointing to the first line of your if statement.) Because I just copied and pasted, I perpetuated your omission of the double quote at the end of the first print statement, but even after I caught and corrected that, I continue to get the parse error. (And I'm just as perplexed by that! This page ought to work, near as I can tell - but it just doesn't.) The only other odd thing I noticed was that my very first $_GET['ws'] had backquotes surrounding ws. Not sure if this came from my text editor or what, but correcting it didn't fix the problem.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Jan 19th, 2007, 19:08
Reputable Member
Join Date: Mar 2005
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Posts: 245
Thanks: 6
Thanked 0 Times in 0 Posts
Re: I don't _GET it!

I also tried inserting a listvars function that I've used to debug other troublesome pages in the past. Here's the complete code now:
Code: Select all
<?php
function listvars($v) { 
    global $a; 
    echo "<blockquote>\n"; 
    $q= "while(list(\$key,\$val) = each($".$v. ") ) { ". 
    " echo \"<b>\$key</b>=>\$val.<br>\";". 
    " if(( is_array(\$val)) && (\$key != \"GLOBALS\")) {". 
    " @dd( \$v.\"[\".\$key.\"]\" );". 
    "}}"; 
    eval($q); 
    echo "</blockquote>\n"; 
    } 
$thissite = $_GET['ws'];
print "thissite = '$thissite'";
if (empty ($thissite)) $thissite = "stickpuppy.com";
$cssfile = "stickpuppy.css";
$linkimg_class = "lilpuppy_lr";
$linkimg_src = "img/lilpuppy.jpg";
$admin_email = "webmojo@$thissite";
$guest_email = $_POST['Email'];
$msg_ = $_POST['Message'];
$msg = str_replace("\r", '<br />', $msg_);
listvars("GLOBALS");
I can post the rest of the file, if anyone thinks it will help, but it's just form data/POST data handling; I'm pretty sure the problem lies in the code I've posted. If you want to have a look at the output of that page, here's a link: http://stickpuppy.com/contact_listva...site=dhs57.com I hope someone will see something I've missed.

The page works perfectly except for the stupid querystring. If you want to try it out, feel free: http://stickpuppy.com/contact.php?site=dhs57.com

The only other thought I have is that somehow, maybe this is a problem on the server. Is it possible to disable querystring handling??? My webhost is 1and1.com - are there known issues with their php hosting?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Jan 19th, 2007, 20:54
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Re: I don't _GET it!

The phpinfo confirms that the script IS picking up the parameters from the form - see under PHP Variables; they're listed there. And I host some
of my domains on 1and1 and there's quite a bit of PHP there.

I find myself looking at odd things such as back quotes and forward quotes - or even other special quotes in other fonts. Have you tried with
$thissite = $_GET["ws"];
rather than
$thissite = $_GET['ws'];

By the way - I confirmed the relationship between $_GET and $_REQUEST because I thought the thread might mislead other readers the way it was developing. Sorry if it read otherwise
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Jan 19th, 2007, 21:05
Reputable Member
Join Date: Mar 2005
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Posts: 245
Thanks: 6
Thanked 0 Times in 0 Posts
Re: I don't _GET it!

Quote:
Originally Posted by grahame View Post
Have you tried with
$thissite = $_GET["ws"];
rather than
$thissite = $_GET['ws'];
No, that's one I haven't tried, but I will. Thanks for the suggestion. As for the $_GET/$_REQUEST issue, no offense was taken or anything; I just wanted to illustrate the I do know a little php!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old Jan 19th, 2007, 21:18
Reputable Member
Join Date: Mar 2005
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Posts: 245
Thanks: 6
Thanked 0 Times in 0 Posts
Re: I don't _GET it!

Well, I tried the double quotes. Still no joy. I also thought to try it in IE, on the longshot chance this was some sort of Firefox bug. Same behavior in IE.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old Jan 19th, 2007, 22:30
Reputable Member
Join Date: Mar 2005
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Posts: 245
Thanks: 6
Thanked 0 Times in 0 Posts
Re: I don't _GET it!

Well, I have a workaround... Source page code:

Code: Select all
<form name="contact" action="http://stickpuppy.com/contact.php" method="post">
<input type="hidden" name="re_site" value="dhs57.com">
<a href='javascript:document.contact.submit();'>contact</a>
</form>
Contact form code:

Code: Select all
$thissite = $_POST['re_site'];
I'm not crazy about using javascript for this, but I didn't want to use some generic html button, either. I guess it'll do until I figure out what the problem is.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old Jan 20th, 2007, 11:05
masonbarge's Avatar
Highly Reputable Member
Join Date: Jan 2006
Location: Atlanta GA
Posts: 631
Thanks: 0
Thanked 0 Times in 0 Posts
Re: I don't _GET it!

GAH! Javascript = surrender. It defeats one of the purposes of a serverside language, i.e. 100% certainty.

There is a flaw in the code somewhere. Why don't you try posting all the applicable code in one reply? I have done a lot of links just like this and it's a great technique to automate an unlimited menu of pages. I did a page where the database had articles written, and php automatically generated the new link and page using your exact code, i.e. href="...?id=mysqlid" as the pattern link and $id=$_GET['id'] on the new page.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #13  
Old Jan 20th, 2007, 17:00
Reputable Member
Join Date: Mar 2005
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Posts: 245
Thanks: 6
Thanked 0 Times in 0 Posts
Re: I don't _GET it!

Quote:
Originally Posted by masonbarge View Post
GAH! Javascript = surrender.
I agree, but surrender is about where I'm at right now! And if it comes down to using javascript or a butt-ugly submit button, I'm going with javascript.
Quote:
I have done a lot of links just like this and it's a great technique to automate an unlimited menu of pages.
Yeah, I've used it extensively on ASP, but I'm still learning the ropes on the php side.

OK - bizarre new development - I changed this:
Code: Select all
$thissite = $_GET['ws'];
to this:
Code: Select all
$thissite = ($_GET['ws']);
and it worked! (Well, sort of.)
On a whim, I changed it back - and it still worked! (Well, sort of.)

By sort of, I mean to say that the print statement yields the passed qs parm, and the input I stuck on the form for debugging has the right value in it as well. But when the e-mail is sent out, it still shows "re: stickpuppy.com" in the subject (instead of "re: whatever.net") - but that's just a minor error somewhere else in the code.

I know the documented changes I posted above probably have nothing to do with why it started working, but I don't care. I'm just glad to get past that hurdle.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #14  
Old Jan 20th, 2007, 19:12
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: I don't _GET it!

Below is the code from two test files that I tried and it works perfectly.

Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Page title</title>
</head>
<body>

<a href='phptesting.html?valuepassed=testedok'>click here</a>

</body>
</html>
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Page title</title>
</head>
<body>

    <?php
       $value = $_GET['valuepassed']; 
       print ($value);
   ?>
</body>
</html>
Just a note: these files have the .html extention because my hosting is set to process these files through the php parser.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #15  
Old Jan 20th, 2007, 19:23
Reputable Member
Join Date: Mar 2005
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Posts: 245
Thanks: 6
Thanked 0 Times in 0 Posts
Re: I don't _GET it!

Thanks, Geoff. Mine was pretty much the same, I think. At this point I've made so many changes trying to debug that I can't be certain, but I posted the code in previous posts above and it doesn't look any different now (except for changing a variable name and fixing other problems downstream - which I found after this crazy thing started working!)

edit: Initially, my code looked exactly like the code mason posted here: http://www.webforumz.com/php-forum/1....htm#post87358 - it was immediately preceded by the
PHP: Select all

<?php

tag - which was the first line in the file.

Last edited by Donny Bahama; Jan 20th, 2007 at 19:27.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #16  
Old Jan 20th, 2007, 19:47
Reputable Member
Join Date: Mar 2005
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Posts: 245
Thanks: 6
Thanked 0 Times in 0 Posts
Re: I don't _GET it!

All's well that ends well!

It's working beautifully, and I now have a nice (if I do so say so myself) little contact form. On any page of any of my sites, I can now use a contact link to http://stickpuppy.com/contact.php?ws=webforumz.com

Here's a sample of the confirmation page displayed after the user submits a simple form (name, e-ddress and message text):
Quote:
Your message:
Hey, man- that file is;

"c:\dude\porn.mov"

has been sent to the the_site.com site admin.
A copy of the message has been sent to thedude ot tiki shack dat cam.
Thank you for your correspondence.
Someone will reply as soon as possible.
NOTE: All e-ddresses display normally - they've been obfuscated for this post.
NOTE 2: The use of a semi-colon, double quotes and backslashes was intentional (for testing the escape handling code - which also works nicely).

The user receives an e-mail which looks like:
Quote:
"webmonster ot stick puppy dat cam" to thedude

Subject: Confirmed - your message to the_site.com site admin

Message body:
Your message was sent to the the_site.com site admin:
-----------------------------
From: Jeffrey Lebowski:
E-mail: thedude ot tiki shack dat cam

Message: Hey, man- that file is;

"c:\dude\porn.mov"

-----------------------------
And I receive a message like this one:
Quote:
Jeffrey Lebowski <thedude ot tiki shack dat cam> to webmonster

Subject: Message from thedude ot tiki shack dat cam re: the_site.com

Message body:
Name: Jeffrey Lebowski:
E-mail: thedude ot tiki shack dat cam
re: the_site.com

Message: Hey, man- that file is;

"c:\dude\porn.mov"

-----------------------------
Browser: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1
IP: 6XX.X8X.105.131
I'm sure decent contact forms are a dime a dozen and most everybody probably has one they like already, but if anyone's interested, let me know and I'll post the code for mine. (It even has a little image image bling to lively up the page. )

Last edited by Donny Bahama; Jan 20th, 2007 at 19:50.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
get, querystring

Thread Tools

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 On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] $_GET['ting'] Pages (Safely) With PHP