homepage Welcome to WebmasterWorld Guest from 54.237.213.31
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Passing variables in PHP
Looking for some help finding a good tutorial source
WestCoGuy

10+ Year Member



 
Msg#: 2586 posted 8:51 pm on Jan 17, 2004 (gmt 0)

I am experienced in HTML coding and SQL database use. However, am new to PHP. In the last few days I have learned to successfully create, write to, and pull data from my server's mySQL database; so I'm pleased with the power (and relative simplicity) available!

However, in trying to harvest things like the HTML <title> of my page (to log to my db), or to get variables from HTML <form>, or environmental things like which browser is in use... I'd like to know what would be a good online tutorial or web source to clear the fog here.

Suggestions? Thanks a bunch.

 

Schoolbag

10+ Year Member



 
Msg#: 2586 posted 9:16 pm on Jan 17, 2004 (gmt 0)

try this one:
freewebmasterhelp.com/tutorials/php

they have a great one for php/mysql as well.

[edited by: jatar_k at 12:01 am (utc) on Jan. 18, 2004]
[edit reason] delinked [/edit]

jatar_k

WebmasterWorld Administrator jatar_k us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 2586 posted 12:07 am on Jan 18, 2004 (gmt 0)

Welcome to WebmasterWorld WestCoGuy,

Most of what you are asking is available here

PHP Predefined Variables [ca.php.net]

The superglobal arrays will contain most of what you are looking for.

$_SERVER - user agent, paths, IP and a whole ton more

$_POST - an array of the values posted to the script from a form using the action=POST

$_GET - an array of the values from variables in the url or a form with action=GET

$_COOKIE - variables from cookies

$_ENV - environment vars

and a couple of others.

WestCoGuy

10+ Year Member



 
Msg#: 2586 posted 12:50 am on Jan 18, 2004 (gmt 0)

Thanks. Once I tapped into the $_SERVER stuff, I began to find what I needed.

Using SERVER["REQUEST_URI"], I get "/Filename.php" returned. If I only want "Filename" in a variable (strip the slash and .php), what is a good script or method to do this? I know this is elementary, but I don't want to develop any bad coding habits right at the start.

jatar_k

WebmasterWorld Administrator jatar_k us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 2586 posted 3:08 am on Jan 18, 2004 (gmt 0)

You have to remember that REQUEST_URI gives

The URI which was given in order to access this page; for instance, '/index.html'.

which means the data you get will be somewhat unreliable. I would use SCRIPT_NAME

Contains the current script's path. This is useful for pages which need to point to themselves.

or PHP_SELF

The filename of the currently executing script, relative to the document root. For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar would be /test.php/foo.bar.

it really depends on what you want to do with it.

you could use split [ca.php.net] to chop the paths up on the /, which returns an array of the parts and then grab the last part.

To return the last piece you could count [ca.php.net] the elements in the array and use that -1 and then reference the last element.

WestCoGuy

10+ Year Member



 
Msg#: 2586 posted 3:28 am on Jan 18, 2004 (gmt 0)

Thanks to all. This has been very helpful. Now I'm trying to figure out how to hide the userid and password info required to do SQL queries... sure don't want them in the PHP script! Must be more than one way to skin a cat here...

BitBanger

10+ Year Member



 
Msg#: 2586 posted 2:40 pm on Jan 18, 2004 (gmt 0)

WestCoGuy:
Now I'm trying to figure out how to hide the userid and password info required to do SQL queries... sure don't want them in the PHP script! Must be more than one way to skin a cat here...

The normal way of doing that is to include() the php code that contains the connection information. For added security, place that php code in a directory that is not accessable from the web. This also means that all the connection information is centrally located, making changes a simple matter of changing one file.

Also, unless the server screws up, any php file is not directly available from the web. It should always be parsed by the server, so the username and password are hidden anyway.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved