php.de

Zurück   php.de > Webentwicklung > PHP Einsteiger > PHP Tipps 2005

 
 
LinkBack Themen-Optionen Thema bewerten
Alt 18.04.2005, 21:19  
Gast
 
Beiträge: n/a
Standard Hallo,könnte mir bitte jemand weiterhelfen?"admin.php&a

Hallo,könnte mir bitte jemand weiterhelfen? hab vor n paar tagen ein Newsscript tutorial gefunden das meinen wünschen entsprechen würde...nur komm ich einfach nicht mehr weiter....Ich hoffe jemand von euch kann mir auf die sprünge helfen.

1. Addnews.php
2. news.txt (auf Chmod777 eingestellt)
3. News.php (zum anzeigen der news.txt Datei)
4. Admin.php (Die Datei wo ich nicht mehr weiter weis )

1.Addnews.php

PHP-Code:
<?php
<?
//this should all go into one file. I would name it addnews.php
if($HTTP_POST_VARS['submit']) {
    if(
$HTTP_POST_VARS['password'] == 'pass') {
        if(!
$HTTP_POST_VARS['name']) {
            echo 
"You must enter a name";
            exit;
        }
        if(!
$HTTP_POST_VARS['news']) {
            echo 
"You must enter some news";
            exit;
        }
        if(
strstr($HTTP_POST_VARS['name'],"|")) {
            echo 
"Name cannot contain the pipe symbol - |";
            exit;
        }
        if(
strstr($HTTP_POST_VARS['news'],"|")) {
            echo 
"News cannot contain the pipe symbol - |";
            exit;
        }
        
$fp fopen('news.txt','a');
        if(!
$fp) {
            echo 
"Error opening file!";
            exit;
        }
        
$line date("m.d.y") . "|" $HTTP_POST_VARS['name'];
        
$line .= "|" $HTTP_POST_VARS['news'];
        
$line str_replace("\r\n","
"
,$line);
        
$line .= "\r\n";
        
fwrite($fp$line);
        if(!
fclose($fp)) {
            echo 
"Error closing file!";
            exit;
        }        
    } else {
        echo 
"Bad Password";
    }
}

?>
<FORM ACTION="<?=$PHP_SELF?>" METHOD="POST" NAME="newsentry">
Your name:

<INPUT TYPE="text" SIZE="30" NAME="name">

The News:

<TEXTAREA NAME="news" COLS="40" ROWS="5"></TEXTAREA>


News Password:

<INPUT TYPE="password" SIZE="30" NAME="password">

<INPUT TYPE="submit" NAME="submit" VALUE="Post it!">

</FORM>
?>
2.Admin.php(wo ich nicht weiter weis)

PHP-Code:
<?php
<?
echo 
"<H1><u>Current News</u></H1>\n";
$data file('news.txt');
$data array_reverse($data);
foreach(
$data as $element) {
    
$element trim($element);
    
$pieces explode("|"$element);
    echo 
$pieces[2] . "
"[b]Posted by " $pieces[1] . " on " $pieces[0] . "[/b]

"
;
}
echo 
"<HR>\n";
echo 
"<H1><u>Add News</u></H1>\n";
if(
$HTTP_POST_VARS['submit']) {
    if(
$HTTP_POST_VARS['password'] == 'pass') {
        if(!
$HTTP_POST_VARS['name']) {
            echo 
"You must enter a name";
            exit;
        }
        if(!
$HTTP_POST_VARS['news']) {
            echo 
"You must enter some news";
            exit;
        }
        if(
strstr($HTTP_POST_VARS['name'],"|")) {
            echo 
"Name cannot contain the pipe symbol - |";
            exit;
        }
        if(
strstr($HTTP_POST_VARS['news'],"|")) {
            echo 
"News cannot contain the pipe symbol - |";
            exit;
        }
        
$fp fopen('news.txt','a');
        if(!
$fp) {
            echo 
"Error opening file!";
            exit;
        }
        
$line date("m.d.y") . "|" $HTTP_POST_VARS['name'];
        
$line .= "|" $HTTP_POST_VARS['news'];
        
$line str_replace("\r\n","
"
,$line);
        
$line .= "\r\n";
        
fwrite($fp$line);
        if(!
fclose($fp)) {
            echo 
"Error closing file!";
            exit;
        }
        echo 
"[b]News added![/b]\n";    
    } else {
        echo 
"Bad Password";
    }
}

?>
<FORM ACTION="<?=$PHP_SELF?>" METHOD="POST" NAME="newsentry">
Your name:

<INPUT TYPE="text" SIZE="30" NAME="name">

The News:

<TEXTAREA NAME="news" COLS="40" ROWS="5"></TEXTAREA>


News Password:

<INPUT TYPE="password" SIZE="30" NAME="password">

<INPUT TYPE="submit" NAME="submit" VALUE="Post it!">

</FORM>
?>
(Soweit bin ich gekommen doch nun keinen plan wo das hingehört um den link zu aktivieren der die news löscht.....

Tutorial

Ok, let's make the links actually do something! Let's deal with the delete link first. It is a bit less complicated than the edit link. First thing we will need to do is add a line of code that checks to see if the delete link has been clicked. We will check to see if the $action variable is set to delete with some code like this.

PHP-Code:
<?php
<?php
if($action == "delete") {
?>
?>

Simple enough eh? Ok, now we need to check a password to make sure it is ok to delete it and at the same time we will be confirming the deletion. We are basically going to do the same thing as we would to display all the news, except we are going to use the id we passed to the delete portion of the script to only display the one news item we want to delete.

PHP-Code:
<?php
<?php
if($action == "delete") {
    echo 
"<H2>You are about to delete the following news item.</H2>\n";
    
$data file('news.txt');
    
$element trim($data[$id]);
    
$pieces explode("|"$element);
    echo 
$pieces[2] . "
"[b]Posted by " $pieces[1] . " on " $pieces[0] . "[/b]\n";
    echo 
"

\n"
;
    echo 
"Are you sure you want to delete this news item? If so, enter the password and click on Delete.
\n"
;
    echo 
"<FORM ACTION=\"$PHP_SELF?action=delete\" METHOD=\"POST\" NAME=\"deleteform\">\n";
    echo 
"Password:
\n"
;
    echo 
"<INPUT TYPE=\"password\" SIZE=\"30\" NAME=\"password\">
\n"
;
    echo 
"<INPUT TYPE=\"hidden\" NAME=\"id\" VALUE=\"$id\">\n";
    echo 
"<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Delete\">
\n"
;
    echo 
"</FORM>\n";
    exit;
}
?>
?>

You'll notice that I included a hidden field that holds the id that was passed to the delete portion of the script. The reason I did this is that we will still need this id when we actually delete the news item. Now, what we need to do is add some code that checks to see if the action is set to delete AND the password field of the form has been set.

PHP-Code:
<?php
<?php
if($action == "delete" && isset($HTTP_POST_VARS['password'])) {
?> 
?>

Ok, that should suffice. That line should go to the very top of our script. Definitely make it above the last snippet that checked for an action of delete. If we don't check this first, things won't execute in the order we want them to. Now, let's check the password and then actually delete the news item.

PHP-Code:
<?php
<?php
if($action == "delete" && isset($HTTP_POST_VARS['password'])) {
    
//obviously you should change this password on the next line
    
if($HTTP_POST_VARS['password'] == "deletepass") {
        
$data file('news.txt');
        
//this next line will remove the single news item from the array
        
array_splice($data,$id,1);
        
//now we open the file with mode 'w' which truncates the file
        
$fp fopen('news.txt','w');
        foreach(
$data as $element) {
            
fwrite($fp$element);
        }
        
fclose($fp);    
        echo 
"Item deleted!

\n"
;    
        echo 
"<a href=\"$PHP_SELF\">Go Back</a>\n";
        exit;
    } else {
        echo 
"Bad password!\n";
        exit;
    }
}
?>
?>
Könnt ihr mir bitte weiterhelfen ich hab keine ahnung mehr wo ich den code hinschreiben soll.....Mfg.SilentNoice
 
Sponsor Mitteilung
PHP Code Flüsterer

Registriert seit: 21.08.2005
Beiträge: 4682
PHP-Kenntnisse:
Fortgeschritten

Alt 18.04.2005, 21:22  
Erfahrener Benutzer
 
Registriert seit: 01.06.2004
Beiträge: 721
suendesizer
Standard

*GRUMMEL-NARF* Hier im Forum gibt es sooo schöne [ php ] Tags, da wird dann dein Code sooo schön gehighlightet, so dass man dann auch gerne sich den mal durchliest...
__________________
If you read this message backward, Satan will force you to smoke marijuana.
Gute Tutorials
suendesizer ist offline  
Alt 18.04.2005, 21:30  
Erfahrener Benutzer
 
Registriert seit: 11.07.2004
Beiträge: 269
function
function eine Nachricht über ICQ schicken
Standard

naja also eine kleine anmerkung meinerseits nimm $_POST[] statt$HTTP_POST_VARS[] ist kürzer nud wird heute so gemacht. dann naja ich weiss nicht wirklich was du brahcst suchst du sowas:
<a href=\" ".$_SERVER['PHP_SELF']."?action=delete\"> löschen </a>
dann muss aber in den if abfragen immer statt $action $_GET['action'] stehn
__________________
Es ist ein großer Trost, andere dort scheitern zu sehen, wo man selbst gescheitert ist. (William Somerset Maugham)
function ist offline  
Alt 18.04.2005, 21:37  
Gast
 
Beiträge: n/a
Standard

Ähmm..also ich kenn mich fast überhaupt nicht aus mit php.... gebe ich offen zu....

hier ist der link zum NEWS tutorial... http://codewalkers.com/tutorials/7/1.html

abschnitt Delete News da komm ich nicht weiter keine ahnung wo der code hin kommt.....Mfg.SilentNoice
 
Alt 18.04.2005, 21:44  
Erfahrener Benutzer
 
Registriert seit: 11.07.2004
Beiträge: 269
function
function eine Nachricht über ICQ schicken
Standard

ich bin mal so frei dir nen link zu einer deutsch sprachigen seite zugeben:
http://tut.php-q.net da gibts auch ein news script das dir verständlicher ein scheinen sollte.
achja mit tutorial ist nicht gemeint code schnippsel zukopieren und dann fertig ist das script sondern eher man sieht wie es im tutorial gemacht wird und passt das script dann seinen wünschen an und verbessert es gegebenen falls
__________________
Es ist ein großer Trost, andere dort scheitern zu sehen, wo man selbst gescheitert ist. (William Somerset Maugham)
function ist offline  
Alt 18.04.2005, 22:30  
Gast
 
Beiträge: n/a
Standard

Danke für den Link
aber ich brauch kein Newsscript mit SLQ
Ich will ja nur wissen wo der codeschnippsel hinn gehört....

(Bitte macht es nicht unnötig kompliziert :wink: )
 
Alt 18.04.2005, 22:44  
Erfahrener Benutzer
 
Registriert seit: 14.04.2005
Beiträge: 1.004
search
Standard

Übersetzt ^^
eventuell hilfts dir ja so weiter...
aber ich denke auch dass du dir eher ein tutorial wie ein buch vorstellen musst aus dem kannste auch nicht blöd rauskopieren sondern musst es auch zumindest abschreiben aber dazu gehört auch schon ein wenig mehr.

so wie ichs verstanden habe gehört der schnipsel in die admin.php aber ich kenne keine einzige codezeile von dem ding also angaben ohne

greez search
search ist offline  
Alt 18.04.2005, 22:48  
Gast
 
Beiträge: n/a
Standard

Danke ....search

Du hast mir schon ziemlich weitergeholfen....aber wo und wie das in die admin.php gehört.
 
Alt 18.04.2005, 22:57  
Erfahrener Benutzer
 
Registriert seit: 14.04.2005
Beiträge: 1.004
search
Standard

o man ^^
das is eine einzelne php datei so wie ich das sehe
http://codewalkers.com/tutorials/7/5.html
kopieren einbaun bumm fertig ...
schön is sicher was anderes aber bitte

... search
__________________
schlimmer gehts nimmer.... dümmer immer!
search ist offline  
Alt 18.04.2005, 23:05  
Gast
 
Beiträge: n/a
Standard

Ojee das hab ich ja garnicht gesehen.... Danke vielmals...COOOOLL Mfg.SilentNoice
 
 


Themen-Optionen
Thema bewerten
Thema bewerten:

Forumregeln
Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are an
Gehe zu

Besucher kamen über folgende Suchanfragen bei Google auf diese Seite
php passwort name hallo admin bestellen, if ($http_post_vars[\submit\])

Alle Zeitangaben in WEZ +2. Es ist jetzt 09:26 Uhr.




Powered by vBulletin® Version 3.7.2 (Deutsch)
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
Aprilia-Forum, Aquaristik-Forum, Liebeskummer-Forum, Zierfisch-Forum, Geizkragen-Forum

Creative Commons License
Dieser Inhalt ist unter einer Creative Commons-Lizenz lizenziert.