Welcome to WebmasterWorld Guest from 54.160.163.163

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Passing variables in PHP

Looking for some help finding a good tutorial source

     

WestCoGuy

8:51 pm on Jan 17, 2004 (gmt 0)

10+ Year Member



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

9:16 pm on Jan 17, 2004 (gmt 0)

10+ Year Member



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

12:07 am on Jan 18, 2004 (gmt 0)

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



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

12:50 am on Jan 18, 2004 (gmt 0)

10+ Year Member



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

3:08 am on Jan 18, 2004 (gmt 0)

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



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

3:28 am on Jan 18, 2004 (gmt 0)

10+ Year Member



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

2:40 pm on Jan 18, 2004 (gmt 0)

10+ Year Member



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.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month