/    Sign up×
Community /Pin to ProfileBookmark

rewriteMAP and PHP+MySQL

Hello, im starting mad with this problem:

I would like to redirect the users from the page [B][url]http://www.mysite.com/team.php?id=12[/url][/B] to the URL [B]http:[url]www.mysite.com/nameteam[/url][/B]

to do this I have changed th httpd file of Apache adding this code:

[B]

[CODE]RewriteMap team prg:/home/www/web/include/userdir.php
RewriteRule ^/team/(.*)$ /team.php?id=${team:$1} [L,R][/CODE]

[/B]

the userdir.php is a prg in php which read from a mysql table the nameteam from the id.

This is the code:

[code=php]#!/usr/local/web/php/bin/php
<?php

$fdin=fopen(“php://stdin”,”r”);
$fdout=fopen(“php://stdout”,”w”);
set_file_buffer($fdout,0);
while($l=fgets($fdin)) {
fputs($fdout,key_lookup($l));
}
function key_lookup($key) {
$hostname_conn_ht = “localhost”;
$database_conn_ht = “db”;
$username_conn_ht = “dbuser”;
$password_conn_ht = “secret”;
$conn_ht = mysql_pconnect($hostname_conn_ht, $username_conn_ht, $password_conn_ht) or trigger_error(mysql_error(),E_USER_ERROR);

mysql_select_db($database_conn_ht, $conn_ht);
$query_rec = sprintf(“SELECT id FROM `user` WHERE team = ‘%s'”, $key);
$rec = mysql_query($query_rec, $conn_ht) or die(mysql_error());
$row_rec = mysql_fetch_assoc($rec);
$totalRows_rec = mysql_num_rows($rec);
if ($totalRows_rec>0) return $row_rec[‘id’];
else return $key;
mysql_free_result($rec);
}
?>[/code]

But it dos’nt works!

If I try to join [url]www.mysite.com/mynameteam[/url]

I can loo the URL change in [url]www.mysite.com/team.php?id=mynameteam[/url]

instead of [url]www.mysite.com/team.php?id=12[/url]

This seem becouse $totalRows_rec = 0 but i m sure “mynameteam” is in the db! Infact i have tryed cahnging the query in

[CODE]sprintf (SELECT id FROM `user` WHERE team = ‘%s'”, “mynameteam”)[/CODE]

and it is working.

A secondary Question:

I know the RewriteRule is it wrong and i would like to change it when i ll resolve the php problem, I don’t want the users will see the URL change. How i have to change this to redirect without change the URL in the window ?

Thanks! A lot for your time!

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @uncoke spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...