Jump to content

[SOLVED] Form to edit a redirecting table


saariko

Recommended Posts

Hi,

 

As this is my first post here, I hope I can get the help I need.

 

I am looking for a page/form to be able to edit one of our redirecting tables.  Basiclly, we have a page: convert.php  where the value entered in page=XXX , is getting redirected to an alternate page.

 

The convert.php is:

<?php
#The address is:
# it will use the variable "source" from the calling page.
# please keep the table clean as possible
#http://wwww.domain.com/convert.php?source=

$redirecting_from=$_GET['source'];

if($redirecting_from == "youtube"){
        Header("Location: http://www.youtube.com/");
} elseif($redirecting_from == "cnn"){
        Header("Location: http://www.cnn.com/");
} elseif($redirecting_from == "help_en"){
        Header("Location: http://wwww.domain.com/Help/en/");
} elseif($redirecting_from == "test"){
        Header("Location: http://wwww.domain.com/wszsmf");
} elseif($redirecting_from == "staff"){
        Header("Location: http://wwww.domain.com/rxscwb");
} elseif($redirecting_from == "brochure"){
        Header("Location: http://www.domain.com/files/2008Brochure_lowres.pdf");
} elseif($redirecting_from == ""){
        Header("Location: ");
}else {
        Header("Location: http://www.domain.com/");
}

 

I want to give my users the ability to edit the name=value pairs, so they can do it on their own. They do not have access to my root, so the only/best option will be give them some php form to do it.

 

Thanks

 

p.s.

After reading this, it looks like homework, well, it isn't. My domain is: http://www.optitex.com, and you can actually visit us :-)

Link to comment
Share on other sites

You can have a form, where you tell a user to enter the "keyword" and "url" with a comma seperated on each line.

 

IE: (Text area)

cnn, http://www.cnn.com

help_en, http://www.domain.com/Help/En/

 

etc.

 

Then just access these via the database, explode at the comma then run through that if for the user.

 

Just be wary, this can be problematic if a user wants it to be.  I would do some heavy checks on what is inputted in that form etc.

 

Link to comment
Share on other sites

So I may have 3 files than

 

values.inc  (a simple text file, each entry is a line with comma)

name1, url1

name2, url2

name3, url3

 

form.php

to populate (might want to limit with regex to characers and number only, no special chars)

 

and convert.php

can simple go over the values.inc and take the second value.

 

cheers, will try to work on that.

Link to comment
Share on other sites

Just to let everyone know, I have solved this, please find the 3 files I use:

 

1. the values page is a comma seperated pair file.

 

2. the process page

<?php
// Get a file into an array.  In this example we'll go through HTTP to get
// the HTML source of a URL.
$lines = file('values.inc');

// Loop through our array, show HTML source as HTML source; and line numbers too.
foreach ($lines as $line_num => $line) {

        $pair = split (',' , $line);

        if ($pair[0] == $_GET['id'])
                Header("Location: " . $pair[1]);
}

 

 

the 3rd file, which does the work (and can be tweaked more)

<html>
<body>
<?php
$short = $_POST['shortname'];
$redirect = $_POST['redirect'];
?>

<form action="editlink.php" method="post">
<p>short name <input type="text" name="shortname" /><br />
re-direct to: COMPLETE ADDRESS PLEASE.<input type="text" name="redirect" /></p>

For example:<br>
short = help_en<br>
re-direct = http://www.site.com/Help/en <br>

The example gives you the option to use: http://www.site.com/pid.php?id=[sHORTVALUE]<br>
and it will redirect you the the long url.<br>


<p><input type="submit" value="Send it!"></p>
</form>
<?php
$lines = file('values.inc');
$newval = true;


echo "<P><B>You can send the first URL to the customer</B> <BR>";

foreach ($lines as $line_num => $line) {

        $pair = split (',' , $line);
        echo "http://www.site.com/pid.php?id=" . $pair[0] . "\t --> <a href='" . $pair[1] ."'>" . $pair[1] . "
</a><BR>";

        if ($pair[0] == $short)
                $newval = false;

}

if ( !empty($short) && $newval ) {
        $MyFile = fopen('values.inc', 'a+');
        fwrite($MyFile, $short . "," . $redirect . "\n");
        fclose($MyFile);
        $newval = false;
}

?>


</body>
</html>

 

 

Cheers, and thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.