0

Hi Guys :) erm Im not the biggest on Javascript its more like a second language unlike PHP and HTML erm anyway, I am trying to redirect users with Javascript, the reason I am using javascript is so that users don't see the URL, its more of a precaution on my part.

Anyway my problem is:

Users can have several rows (message system) and each row has a title saying 'private message from BLA' so each row equals a new row in the database meaning If there were four the url's of the rows would go like e.g.

message?id=1
message?id=2
message?id=3
etc...

But my javascript redirect is only compensating for one row so all my rows are going by the first row for that user..
Is there a way to make it redirect for multiple custom id/urls..

my current Javascript is basic:

<script language="JavaScript">
function onClick(event)
{
window.location = "console-view?id=<? echo"$find[id]"; ?>";
}
//-->
</script>

My Rows are done like so:

$user = $loggedin[name];
$mail = mysql_query("SELECT * FROM `messenger` WHERE `reciever`='$user' ORDER BY `id` DESC limit `8`");
while($find = mysql_fetch_array($mail)){ ?>
<div id="Arow"><a onclick="return onClick(href)">Private message from BLA</a>
<? } ?>

I am grateful for any help I receive,
thank you in advance!

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Airshow
0

Public_I,

function redirect(url) {
  window.location.href = url;
}
$user = $loggedin[name];
$mail = mysql_query("SELECT * FROM 'messenger' WHERE 'reciever'='$user' ORDER BY 'id' DESC limit '8'");
while($find = mysql_fetch_array($mail)){
  $id = 'expression to make redirect id for this iteration of the loop';
  $url = 'whatever.php' . '?id=' . $id;
?>
<div id="Arow"><a onclick="return redirect('$url')">Private message from BLA</a>
<? } ?>

However, the URLs will not be hidden from the user as they will always appear in the browser's address bar when the new page is displayed. This is unavoidable with javascript redirects.

Airshow

Edited by Airshow: n/a

0

Hmm I suppose :) but you at least made it work :D im so glad thank you so much for your help!

0

However, you can get tricky.

Make a lookup hash in php in your console-view page and just pass a lookup index as the id.

In main page :

$user = $loggedin[name];
$mail = mysql_query("SELECT * FROM 'messenger' WHERE 'reciever'='$user' ORDER BY 'id' DESC limit '8'");
var $count = 0;
while($find = mysql_fetch_array($mail)){
  $id = $count++;//a simple incremental, but could be any rule you want
  $url = 'whatever.php' . '?id=' . $id;
?>
<div id="Arow"><a onclick="return redirect('$url')">Private message from BLA</a>
<? } ?>

In console-view, implement the lookup :

...
$url_lookup = array();
$url_lookup[0] = "http://www. ........";
$url_lookup[1] = "http://www. ........";
$url_lookup[2] = "http://www. ........";
...
$url = $url_lookup[$_GET['id']];

Then, so long as you implement the server-side redirect correctly, the user will not see the url.

Airshow

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.