tags:

views:

58

answers:

3

hi guys

I want to do something but cant figure out how to do this (i m newbie in php)

suppose, i have a list of URL's which shows live with this preg_replace,

$html = preg_replace('/\s(\w+:\/\/)(\S+)/', ' <a href="http://localhost/get.php?url=\\1\\2" target="_blank"> GO</a> ', $html);

my output is like

http://localhost/get.php?url=http://yahoo.com

its obvious that you can view that links at output page, now i want to hide them at front page and make them clickable and working

something like we can change links into variables and then call them by clicking and something works in backgroud which can perform same thing as we are clicking on the link at front page

ya it seems bit confusing :(

A: 

I'm sorry, maybe I'm not understanding quite well, but, isn't best approch use an array for in side server and use another Get variable to do that?

for example ?link=yahoo

and then

find link in array of url?

BY the way, I'm using NoScript and reports me like a warning..

raulricardo21
A: 

you could save the url into a $_SESSION vars and when some users click the link retrive the url from $_SESSION and redirect to it...

//page1 - parse, save link in session and print a call to page2
<?php
session_start();
$_SESSION['url'] = preg_replace('/\s(\w+:\/\/)(\S+)/', ' <a href="http://localhost/get.php?url=\\1\\2" target="_blank"> GO</a> ', $html);
 .... 
echo '<a href="./page2.php">GO</a>';
?>
//page2 
<?php
session_start();
header('Location: '.$_SESSION['url']);
?>

If i undeerstood what you meant...

Obviously now I used $_SESSION['url'] as a single string, but you can use a multidimensional array intead...

UPDATE:

anyway is better if you use an array on script.. example: http://www.test.org/go.php?page=# (where # is a number)

<?php

$array=("http://www.google.com","http://stackoverfloc.com","ecc");
//you can add more contorl in if statement, like between etc...
if (is_numeric($_GET['page']) header('Location: '.$array[$_GET['page']]);
?>
Marcx
i guess this is what i m looking for, because links are not static they are changing every second, it still need lots of work somethings are over my head lol
Jake
you can als use a matrix to a determintated value to the url... if you need help just ask...
Marcx
A: 

You build up links with looking like this:

yourdomain.com/redirector.ph?url=#

where # represents an identifier.

In redirector.php you check if you know that identifier and send the redirect HTTP Header:

header("Location: http://www.example.com/");

Important Note:

You may not send any data before sending the header and the code after sending it won't be executed.

Info

http://php.net/manual/en/function.header.php

EDIT

Using this header is not absolutely proper in regards to standard, but it's not too far off, as the response really is at another location.

PvB