TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 09-11-2008, 10:26 PM   #1 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default passing variables through a url

hello,

i have a url like this: index.php?category=something

when i try to echo out $category on my local computer it doesnt work but when i try it on a hosting server it works

why wont it work locally?
i put register_globals to on.

anyone know?
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 09-11-2008, 10:29 PM   #2 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

What's your code? Are you using short PHP tags?
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Old 09-11-2008, 10:33 PM   #3 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

Quote:
Originally Posted by ETbyrne View Post
What's your code? Are you using short PHP tags?
no im doing long tag <?php

ok here is my code

this is the left navigation categories so when one of them is clicked the page will redirect to it.
Code:
<?php
#======================================
#  DISPLAY CATEGORIES
#======================================

$query = mysql_query("select category from tbl_category where visible = 'yes'") or die(mysql_error());
while($row = mysql_fetch_assoc($query)) {


echo "<a href=\"index.php?category=d\">{$row['category']}</a><br>";
}

#======================================
?>
once redirected it will show this

Code:
<?php
#======================================
#  Listing
#======================================

echo "Category:".$category;

#======================================
?>
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 09-12-2008, 01:07 AM   #4 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

Shouldn't you declare $catagory before using it?

PHP Code:
<?php
#======================================
#  Listing
#======================================

$catagory $_GET['catagory'];

echo 
"Category:".$category;

#======================================

# or you could do this...

echo "Category:".$_GET['category'];
?>
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Old 09-12-2008, 09:35 AM   #5 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Steer well clear of register_globals, they are downright daft as well as posing a considerable security issue if not done correctly.

Use the super globals:
PHP Code:
$_GET[];
$_POST[];
//or even use request, which is a fudge of the two above arrays as well as cookie data
$_REQUEST[]//contains  GET POST and COOKIE 
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 09-12-2008, 01:36 PM   #6 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
ReSpawN is on a distinguished road
Default

Best way to pass it it definitly through GET's, unless you're posting (huge) amounts of data. Then, of course, you can use POST or rather use a database.

For later use, you can also save it encoded into a Cookie, and remove it when you're done. (first setcookie with the data, and then the same but with empty values)
__________________
"Life is a bitch, take that bitch on a ride"
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
Old 09-12-2008, 10:15 PM   #7 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

my page doesnt have a form on it , im grabbing the variables directly from the url

so if the url was index.php?category=cell phones

if i did the following on the server it would work but not on my pc

echo $category , the output would show cell phones

if im not using a form method such as post or get how would post or get even work?
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 09-12-2008, 10:46 PM   #8 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

Data that is passed through a URL is considered form data.

Just try this:
PHP Code:
echo $_GET['category']; 
so if you view the page index.php?category=Yeah Toast the output would look like this:
Code:
Yeah Toast
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Old 09-13-2008, 11:20 PM   #9 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
ReSpawN is on a distinguished road
Default

An even better way, to make sure that it all comes through, is base64 encoding.

There are so much ways to do this. I mostly do this trough encoding the string that I want to send, and then decoding it on the other send.

?this=a2lua3ksIGp1c3QgdHJ5aW5nIHRvIHNlZSBpZiB5b3UgYXJlIG dvaW5nIHRvIGRlY29kZSB0aGlzLg==

Base64 Encoder and Decoder

What you can do, if you want to send entire arrays, first serialise() the array, and then encode it as base64. When you want to retrieve it, decode it and then unserialise() it.
__________________
"Life is a bitch, take that bitch on a ride"
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
Old 09-13-2008, 11:47 PM   #10 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,381
Thanks: 5
Salathe is on a distinguished road
Default

Quote:
Originally Posted by sarmenhb View Post
if im not using a form method such as post or get how would post or get even work?
GET and POST are not simply 'form methods' but varieties of HTTP Request Methods, as such forms aren't necessary to send such requests. Indeed, a normal page request like the one that brought you to this page will have been using a GET request and any query string arguments (if any) will be available in the superglobal $_GET array.
Salathe is offline  
Reply With Quote
The Following User Says Thank You to Salathe For This Useful Post:
sarmenhb (09-14-2008)
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 04:44 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design