Home Forums Gamescan Chat42 About
* Login   * Register * FAQ    * Search
It is currently Fri 03-29-2024 6:51AM

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: php question
PostPosted: Sun 07-11-2004 12:49PM 
Offline
Pointless Post Specialist
User avatar

Joined: Mon 04-21-2003 2:54PM
Posts: 1826
Location: KC

Source: Off Campus
Alright, so I'm messing around with some php on my site. I haven't been able to find anything on this on any online resources.

Say if a link is:
somethingstupid.com/crap.php?variable=value&anotherone=somethingelse

How do I use the variables in the code? Is it just like this?
Code:
<?php
  echo $value . $somethingelse;
?>


Or do I have to do something like you do with postdata?

Also, anybody know any good actual books that would be a good resource for php, java, and that kind of thing. I'm trying to learn it, and I'm sick of searching for reliable info online.

_________________
Aw man, I shot Marvin in the Face!


Top
 Profile  
    
 Post subject:
PostPosted: Sun 07-11-2004 1:23PM 


Source: Somewhere
I don't know if this is what you are looking for or not, but eh.. worth a shot right? If you have a website, say whatever.com/index.php?user=bob use $HTTP_GET_VARS['user'] to "rip" bob out of the user variable.

Code:
<?php
   $user = $HTTP_GET_VARS['user'];
   echo $user;
?>


Additional variables can be added by calling $HTTP_GET_VARS again with the other variable name. http://www.php.net is a great resource for finding code that is usually better than any book. If you really want to pay for a book, go ahead but between google and php.net you should be able to find just about anything you're looking for.


Top
  
    
 Post subject:
PostPosted: Sun 07-11-2004 1:41PM 


Source: Somewhere
I'd just like to point out that in my last post I used the same name for the user in the URL and the $user string, I thought that might have been kind of confusing, so I just wanted to make it clear what I was trying to do with that. You use $HTTP_GET_VARS on the variable in the URL. So, in your example of somethingstupid.com/crap.php?variable=value&anotherone=somethingelse
you'd use.

Code:
<?php
   $foo = $HTTP_GET_VARS['variable'];
   $bar = $HTTP_GET_VARS['anotherone'];

   echo $foo .  " " . $bar . "\n";
?>


The output should be:

value somethingelse\n

But, yeah I have way too much free time on my hands, so I'll stop now.


Top
  
    
 Post subject: Re: php question
PostPosted: Sun 07-11-2004 6:02PM 
Offline
Colonel
User avatar

Joined: Mon 04-15-2002 4:23PM
Posts: 516
Location: Far, far away from Rolla (Colorado to be exact)

Source: Off Campus
hdncollision wrote:
Also, anybody know any good actual books that would be a good resource for php, java, and that kind of thing. I'm trying to learn it, and I'm sick of searching for reliable info online.


Core Java 1 & 2 (Sun Press) is great for Java in general. If you are wanting to do stuff with web services then Java Servlet Programming (O'Reilly) is pretty good too. The last is a little dated and just kind of briefly (read: not very helpful for 2.3 additions) goes over the Servlet 2.3 specification (the book won't tell you much about filters and stuff) but is still pretty good.

_________________
That's right. I'm gone. Rolla couldn't hold me. If you are still there, I know your pain. But I'm still going to laugh at you from far, far away. :-P


Top
 Profile E-mail  
    
 Post subject:
PostPosted: Sun 07-11-2004 9:16PM 
Offline
Captain
User avatar

Joined: Mon 09-29-2003 9:29AM
Posts: 122

Source: Fidelity
somethingstupid.com/crap.php?variable=value&anotherone=somethingelse

In that url, the arguments would be "variable" and "anotherone". The values for these arguments (value and somethingelse) will be stored in the variables $value and $anotherone if register_globals is enabled in the php.ini file. I am pretty sure this option is disabled by default.

Otherwise the way you get at arguments is thusly:

If your request was sent using the GET method (ie the arguments were passed in the url as in your example), you would use $_GET['variable'] and $_GET['anotherone'] to access the values.

If your request was sent to the server via a form, and using the POST method, you would use $_POST['variable'] and $_POST['anotherone'].

And that's it.

As far as books, I would highly highly recommend the O'Reilly book "Programming PHP". Also, php.net has a really nice function library, complete with examples.

Let me know if you have any more php questions. I should put this knowledge to some sort of use.


Top
 Profile  
    
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group