Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Hiding GET variables in address bar solution

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Hiding GET variables in address bar solution

Postby ppera » Tue Jan 21, 2003 1:21 pm

It is mostly from estetical reasons, not from some protection.

As I know only way to hide GET variables is usage of frames. But in that case I don't like that pressing refresh always put back to start page.
So I made some little PHP script to override it.

index.php has this:

if (!session_is_registered('frpag')) session_register("frpag");
if (!isset($frpag)) $frpag = "index2.php" ;
?>

<head>.....
</head>

<frameset cols="*" rows="*">
<frame src="<? echo $frpag ?>" name="nav" frameborder="0" /> ......

And at begin of all pages stays:

session_register("frpag"); $frpag = $PHP_SELF ;

So pressing refresh resets that page to initial state. It is probably even better than without frame, when refresh keeps variables.
It's prehaps nothing new, but I didn't see it during my lot of search about it last couple days.
User avatar
ppera
New php-forum User
New php-forum User
 
Posts: 11
Joined: Thu Jan 09, 2003 2:11 pm

Postby Joan Garnet » Tue Jan 21, 2003 2:41 pm

Have a lok at this link
http://www.alt-php-faq.org/local/55/
You'll find it very useful
:)
User avatar
Joan Garnet
Moderator
Moderator
 
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars

Postby ppera » Tue Jan 21, 2003 3:00 pm

Well, I saw it during my intensive search.

CURL extensions I can not use by my host (of course).

HTTP Post will not work for database listings and similar...

If (($of)>$l-1){
echo "<a href=".$PHP_SELF."?q=".$q."&of=".($of-$l)."&l=".$l."&cs=".$cs."&r=".$r."><font size='".$navs."' color='".$textc."'><b><</a> " ;
}

This is code fragment for listing. I don't see other way how to realize jump on specific page by listing database.

You may see how it works: http://www.pootnik.com
first page by menus...
User avatar
ppera
New php-forum User
New php-forum User
 
Posts: 11
Joined: Thu Jan 09, 2003 2:11 pm

Postby WiZARD » Wed Jan 22, 2003 9:05 am

Interesting how it is? HTTP Post will not work for database listings and similar... Maby you some there mistaking?
From manual:
Code: Select all
<?php
if ($HTTP_POST_VARS['action'] == 'submitted') {
   print '<pre>';

   print_r($HTTP_POST_VARS);
   print '<a href="'. $HTTP_SERVER_VARS['PHP_SELF'] .'">Please try again</a>';

   print '</pre>';
} else {
?>
<form action="<?php echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post">
   Name:  <input type="text" name="personal[name]"><br>
   Email: <input type="text" name="personal[email]"><br>
   Beer: <br>
   <select multiple name="beer[]">
       <option value="warthog">Warthog</option>
       <option value="guinness">Guinness</option>
       <option value="stuttgarter">Stuttgarter Schwabenbräu</option>
   </select><br>
   <input type="hidden" name="action" value="submitted">
   <input type="submit" name="submit" value="submit me!">
</form>
<?php
}
?>
User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol

Postby ppera » Wed Jan 22, 2003 10:09 am

Sorry Wizard, but I talk here about GET variables, FORM is no good for me (although it could be good because of hidden variables) but I need hyperlinks with lot of variables, and want to hide them from address bar.

This is'n good example:
print '<a href="'. $HTTP_SERVER_VARS['PHP_SELF'] .'">Please try again</a>'; - you have here only URL

I need something like this:
print '<a href="'.$HTTP_SERVER_VARS['PHP_SELF']."?l=". $HTTP_SERVER_VARS['lim'] .'">Lim50</a>';

But it outprints (of course) l=50 after URL....

To explain better: I get filelist from database for download them, so I need hyperlinks for easier jump to diverse pages of list. And by it keep some settings of page. PHP can't pass apropriate variable because it doesn't know what link will user press.
User avatar
ppera
New php-forum User
New php-forum User
 
Posts: 11
Joined: Thu Jan 09, 2003 2:11 pm

Other solution with some Java

Postby ppera » Thu Jan 23, 2003 1:03 pm

Hehe...

With some little Java we can force that text link act as form, so we can use hidden variables. It's by Christopher S L Heng's text 'How to Make a Text Link Submit A Form ' .

Here is example with two variables:

This goes somewhere between head tags:

<script language="JavaScript" type="text/javascript">
<!--
function getst ( se1, se2 )
{
document.stform.l.value = ( se1 ) ;
document.stform.cs.value = ( se2 ) ;

document.stform.submit() ;
}
-->
</script>


This is code for hyperlink with 2 hidden variables:

<form name="stform" method=post action="<? PHP_SELF ?>">
<input type=hidden name="l" > <input type=hidden name="cs" >
<a href="javascript:getst('20', '<? echo $cs ?>')">20 </a>

$cs=..... #code for changing variable

<a href="javascript:getst('30', '<? echo $cs ?>')">30 </a> </form>

Here is first 'variable' actually constant, but it's not relevant.

Variables will be sent as hidden, this is more secure than frame method. Just need to hide displaying from status bar too...
User avatar
ppera
New php-forum User
New php-forum User
 
Posts: 11
Joined: Thu Jan 09, 2003 2:11 pm

Postby Joan Garnet » Fri Jan 24, 2003 1:48 am

Yeah, that's it :)
It's a bit complicated though... Well, it's kind of handy anyway.
ThanX for sharing !
;)
User avatar
Joan Garnet
Moderator
Moderator
 
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars


Return to PHP coding => General

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot], Google Feedfetcher and 5 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.