Page 2 of 2 FirstFirst 12
Results 11 to 20 of 20

Thread: PHP Delete Function

  1. #11
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by djr33
    How does a user navigate to the link? It's the href of the link, yes?
    Using that href, can store it as $link, through php code, not just waiting for it to show up.... I didn't mean it would automatically be there.

    Somehow, you have the url available. Use that url to add the delete link....
    http://..../delete.php?url=urlhere
    And that should delete it.

    There is absolutely no need for an ID as it just ads one step and you'd STILL need the url in the end. Instead of messing with IDs, just use the url itself, which you MUST!!! have available to link the person.
    Ok, i get it now and it makes sense. Just a few minor things. How do i store the link as $link (a variable)? Also, is there any way to have the delete option shown in the admin control panel, but not in the page users see? Perhaps through referer? Thanks

  2. #12
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    1. How does the URL appear in the clickable link? Get it from there, then store as $link.
    <?php $link = "whateverhere"; ?>
    It's easy to set... getting it is harder... but you ARE getting it, so just repeat the process.
    Post the code if you need a more specific example.

    2. Yes. Displaying it only in the admin cp would be php code. You would just use different code for each. Use the normal one alone and change the code for the admin cp. Or, if it's the same script, use an if to check if the user is admin. If so, then display the delete link.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #13
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by djr33
    1. How does the URL appear in the clickable link? Get it from there, then store as $link.
    <?php $link = "whateverhere"; ?>
    It's easy to set... getting it is harder... but you ARE getting it, so just repeat the process.
    Post the code if you need a more specific example.

    2. Yes. Displaying it only in the admin cp would be php code. You would just use different code for each. Use the normal one alone and change the code for the admin cp. Or, if it's the same script, use an if to check if the user is admin. If so, then display the delete link.
    Ok, so if i were to use <?php $link = "whatever"; ?>, would i need to make a new php file for each link that is added? Other than that I get what you are saying, thanks

  4. #14
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    obviously "whatever" is replaced with the link.
    I don't know how you are storing the link, but I know you are. You need to find out how to access that then use it.
    no new php file for each link.

    php is a server side language that outputs html.
    you can have as many sets of php tags (<?php ... ?>) as you want in a document. they are NOT EVER output. The server ("server side" -- get it?) interprets the tags and outputs ONLY html.

    You could use the echo command (aka print, etc.) to output the value of the link in that case.


    This is getting really complicated.

    How much of the script have you written? What does it do at this point?
    Please post the script.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #15
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ok, here is the code i am trying:
    ad_link_process.php
    PHP Code:
    <?php
    require ("includes.php");

    $filename "featured_links.php"// file to write to

    $date date("F j, Y"); //date format

    $error "An error occured while adding new link!";



        
    // Add Text
    $text stripslashes($_POST['text']);
        if (!
    $text) {
        
    $text "<b>Untitled</b>";
        }
        
        
    // Add Link
    if ($link stripslashes($_POST['link'])) {
        
    $add '
    <?php

    $linkurl = "'
    .$link.'";

    if ($user = "jexlinks") {
        print ("<a href="'
    .$linkurl.'">'.$text.'</a> <a href="delete.php">Delete</a>");
        }else{
    print ("<a href="'
    .$linkurl.'">'.$text.'</a>");
    }
    ?>
        
    '
    ;
        

    $links file_get_contents($filename).$add;
        

        
    $file = @fopen($filename"w");
        @
    fwrite($file$links);
        @
    fclose($file);
        
    $message $success;
        }
    else {
        
    $message $error;
        }

    require (
    "link_added.php");


    ?>
    Delete.php
    PHP Code:
    <?
    str_replace
    ("$text""""ad_link_process.php");
    ?>

    <html>
    <head>
    <title>Delete String</title>
    </head>

    <body>
    Link Deleted!
    </body>

    </html>
    Its just simple right now, but the lines are added to featured_links.php without an issue, but nothing is displayed when i try to access that page : / . Not really sure about all the code, but its just the concept i had in my mind
    Last edited by Titan85; 10-17-2006 at 09:01 PM.

  6. #16
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Heh. You're replacing the string in the php page... that's not a valid variable... just wrong.

    str_replace(SEARCH, REPLACE, VARIABLEITSIN);
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #17
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by djr33
    Heh. You're replacing the string in the php page... that's not a valid variable... just wrong.

    str_replace(SEARCH, REPLACE, VARIABLEITSIN);
    No, i am replacing the $text variable so that there is no longer text for the link, i am not replacing any strings.

  8. #18
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    Here this may be of use to you.
    PHP Code:
    function deleteline($del,$filename){
        
    $file file($filename);
        
    ob_start();
        for(
    $i=0;$i count($file);$i++){
            if(
    strpos($file[$i],$del) === FALSE){
                echo 
    $file[$i];
            }
        }
        
    $write ob_get_contents();
        
    ob_end_clean();
        
    $handle fopen('list.txt','w');
        
    fwrite($handle,$write);
        
    fclose($handle);
    }
    //Pass in the search term, then the filename 
    This function deleteline takes two variables. The first is a search term. In this case that would be $text. And the second is the file name. This will delete the entrie line if it finds that search term. Though it should be able to modify a PHP file, I wouldn't reccomend that(huge,huge,huge security risk)

  9. #19
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by blm126
    Here this may be of use to you.
    PHP Code:
    function deleteline($del,$filename){
        
    $file file($filename);
        
    ob_start();
        for(
    $i=0;$i count($file);$i++){
            if(
    strpos($file[$i],$del) === FALSE){
                echo 
    $file[$i];
            }
        }
        
    $write ob_get_contents();
        
    ob_end_clean();
        
    $handle fopen('list.txt','w');
        
    fwrite($handle,$write);
        
    fclose($handle);
    }
    //Pass in the search term, then the filename 
    This function deleteline takes two variables. The first is a search term. In this case that would be $text. And the second is the file name. This will delete the entrie line if it finds that search term. Though it should be able to modify a PHP file, I wouldn't reccomend that(huge,huge,huge security risk)
    Ok, i don't really get what all that script is saying, could you explain it, but if it is too great a security risk (even if in protected folder), then no need to explain it

  10. #20
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    Oh no, my function is safe. It is your possible use of it(from what I can tell) would be unsafe. As for explaining it. Basically it defines a function(deleteline) that will search in a file and delete any line that matches the search term provided. To understand how it works, just look up the various functions I used.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •