GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 05-Apr-2004, 06:13
PenguinJr PenguinJr is offline
New Member
 
Join Date: Feb 2004
Posts: 19
PenguinJr is on a distinguished road

Manipulating URL


Hi guys,

Lets say i've passed a URL of www.wateva.com/test.php?user=$user from a php page that contained the variable $user with these codes.
Code:
$user = $_POST['username']; header ("location: test.php?user=$user");
so when they're taken to the test page they should see http://www.example.com/test.php?user=Bob
for example.

Now...I wanna keep passing the variable of user and when I need it I want to be able to use that variable.

1st question: How do i pass the variable around in the URL from page to page?
2nd question: How do i use it later on, as in how do i assign it to a variable?

Thank you.
Last edited by JdS : 05-Apr-2004 at 08:22. Reason: Use "example.com" when posting EXAMPLE urls
  #2  
Old 05-Apr-2004, 07:10
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Quote:
Originally Posted by PenguinJr
1st question: How do i pass the variable around in the URL from page to page?
PHP Code:

<?php

// initialise the $QS variable
$QS = '';

// appending the user's name, if any, to internal links...
if( isset($_GET['user']) )
   $QS = '?user=' . $_GET['user'];

// ....

// now when you create a link to an internal page...

echo "<a href=\"/page-2.php$QS\">Page 2</a>";
echo "<a href=\"/page-3.php$QS\">Page 3</a>";
?>


Quote:
2nd question: How do i use it later on, as in how do i assign it to a variable?

Thank you.

You retrieve the super global array $_GET['user'].

Be careful, always validate (clean) user supplied data... by using strip_tags() and urlencode() and other similar functions.
  #3  
Old 05-Apr-2004, 07:30
PenguinJr PenguinJr is offline
New Member
 
Join Date: Feb 2004
Posts: 19
PenguinJr is on a distinguished road
thanx, but how exactly do i encode the url?
  #4  
Old 05-Apr-2004, 07:35
PenguinJr PenguinJr is offline
New Member
 
Join Date: Feb 2004
Posts: 19
PenguinJr is on a distinguished road
Quote:
Originally Posted by PenguinJr
thanx, but how exactly do i encode the url?

and also, how do i use it as part of my html links? (the encoded version)
  #5  
Old 05-Apr-2004, 08:16
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
You could try something like this...

PHP Code:

<?php

// initialise the $QS variable
$QS = '';

// appending the user's name, if any, to internal links...
if( isset($_GET['user']) )
{
  // screen the user input data
      // strip any html tags
      $_GET['user']  = strip_tags( $_GET['user'] );
      // remove spaces left over, if any...
      $_GET['user']  = trim( $_GET['user'] );
  // if we got this far and there's still something in $_GET['user'], then
  // it's safe to use...
  if( !empty($_GET['user']) )
  {
    $QS = '?user=' . urlencode( $_GET['user'] );
  }
}

// ....

// now when you create a link to an internal page...

echo "<a href=\"/page-2.php$QS\">Page 2</a>";
echo "<a href=\"/page-3.php$QS\">Page 3</a>";
?>

 
 

Recent GIDBlogProblems with the Navy (Chiefs) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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 Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Manipulating text Files k209310 C++ Forum 0 17-Nov-2003 11:23

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 16:22.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.