/    Sign up×
Community /Pin to ProfileBookmark

I have this code that sends the viewer to a link within my php. I am wondering if I could create multiple links within one php file instead of making a new file for every link. If I am not making sense (most likely not), please tell me and I will do my very best to elaborate. Thanks for your help and have a good day…

Link3 PHP:

<?php
header(‘Location:[url]http://www.whatever.com);[/url]
die();
$f = fopen(‘demo.txt’,’w+’);
fwrite($f,’Test’);
fclose($f);
?>

HTML:

<a href=”/link3.php” class=”sLinks”>Scholarship for Dads</a>

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiJan 14.2010 — You can pass in a url via the query string, but I would be sure to validate against a whitelist. BTW what's the purpose of the file write? Surely that code will never run? And if your files just contain a header redirect, why not link to the URL directly?
Copy linkTweet thisAlerts:
@JerailJan 14.2010 — You could make use of the query string, if you wanted, like this:

[code=php]<?php
$link = $_GET['link'];
switch($link) {
case 3:
header('Location:http://www.whatever.com);
die();
$f = fopen('demo.txt','w+');
fwrite($f,'Test');
fclose($f);
break;
case 4:
// some code...
break;
}
?>[/code]


With the HTML:

[code=html]<a href="redirect.php?link=3" class="sLinks">Scholarship for Dads</a>[/code]

Note that you can retrieve any value from the querytstring (the part of the URI after the '?') by using the superglobal array "$_GET[]".

Also, please use [ PHP ] or [ HTML ] or [ CODE ] tags when posting code.
Copy linkTweet thisAlerts:
@bradleybebadauthorJan 27.2010 — THANKS JERAIL... Works like a charm
×

Success!

Help @bradleybebad 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.3,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...