Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    New Coder
    Join Date
    Mar 2013
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Creating new page on submit

    Hey i was just wondering how to create a new page on the FTP server when they click on the submit button? And also to get a special template into the page. And insert some of the text from the user into the right coding place.

    I have been looking for it for a long time now please help me out.

    PS: If you need any other information to help me i will reply with the info

  • #2
    Regular Coder patryk's Avatar
    Join Date
    Oct 2012
    Location
    /dev/couch
    Posts
    398
    Thanks
    2
    Thanked 64 Times in 64 Posts
    prepare your template, load it to variable using file_get_contents(), use str_replace() to insert data into template, and then save it in propper directory using file_put_contents()

  • #3
    New Coder
    Join Date
    Mar 2013
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by patryk View Post
    prepare your template, load it to variable using file_get_contents(), use str_replace() to insert data into template, and then save it in propper directory using file_put_contents()
    Thanks i'll try it out now if i have any other question could i ask you? Im not so good with php

  • #4
    New Coder
    Join Date
    Mar 2013
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by patryk View Post
    prepare your template, load it to variable using file_get_contents(), use str_replace() to insert data into template, and then save it in propper directory using file_put_contents()
    Im not sure how i can insert the data from the user with str_replace

  • #5
    Regular Coder patryk's Avatar
    Join Date
    Oct 2012
    Location
    /dev/couch
    Posts
    398
    Thanks
    2
    Thanked 64 Times in 64 Posts
    put some markers in your template for example %username% or {date}

    examples how to use str_replace: http://php.net/manual/en/function.str-replace.php

  • #6
    New Coder
    Join Date
    Mar 2013
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by patryk View Post
    put some markers in your template for example %username% or {date}

    examples how to use str_replace: http://php.net/manual/en/function.str-replace.php
    Could you give me an example because i got to replace 6 things in the template
    i have importet two things like this echo file_get_contents("clockstart.php", "creator.php"); creator.php is were the user information comes from and clockstart.php is the template. But could you give me an example code for replacing info from creator into clockstart and save it. If you could that would be great

  • #7
    Regular Coder patryk's Avatar
    Join Date
    Oct 2012
    Location
    /dev/couch
    Posts
    398
    Thanks
    2
    Thanked 64 Times in 64 Posts
    ok here's the example:
    PHP Code:
    $name 'John';
    $phone '123123123';
    $email 'someone@example.com';

    //get template
    $template file_get_contents('template.html');

    //put data in template
    $template str_replace('%name%'$name$template);
    $template str_replace('%phone%'$phone$template);
    $template str_replace('%email%'$email$template);

    //save file
    file_put_contents($name '.html'$template); 
    and echo file_get_contents("clockstart.php", "creator.php"); makes no sense. file_get_contents takes one file name as a parameter.

  • Users who have thanked patryk for this post:

    sebbi99 (03-27-2013)

  • #8
    New Coder
    Join Date
    Mar 2013
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Smile

    Quote Originally Posted by patryk View Post
    ok here's the example:
    PHP Code:
    $name 'John';
    $phone '123123123';
    $email 'someone@example.com';

    //get template
    $template file_get_contents('template.html');

    //put data in template
    $template str_replace('%name%'$name$template);
    $template str_replace('%phone%'$phone$template);
    $template str_replace('%email%'$email$template);

    //save file
    file_put_contents($name '.html'$template); 
    and echo file_get_contents("clockstart.php", "creator.php"); makes no sense. file_get_contents takes one file name as a parameter.
    Hey Patryk Thank you for all the help from you but could you please say whats wrong with this code?

    PHP Code:
    <?php
    $year 
    $_POST['year'];
    $month $_POST['month'];
    $days $_POST['days'];
    $time $_POST['time'];
    $dn $_POST['dn'];

    //link generator
    $length 10;

    $randomString substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0$length);

    //get template
    $template file_get_contents('clockstart.php');

    //put data in template
    $template str_replace('{iyear}'$year$template);
    $template str_replace('{imonth}'$month$template);
    $template str_replace('{iday}'$days$template);
    $template str_replace('{iclock}'$time$template);
    $template str_replace('{idn}'$dn$template);

    //save file
    file_put_contents($randomString '.php'$template);
    ?>

  • #9
    Regular Coder patryk's Avatar
    Join Date
    Oct 2012
    Location
    /dev/couch
    Posts
    398
    Thanks
    2
    Thanked 64 Times in 64 Posts
    i have no idea. are you getting errors?
    it looks good to me. it should take your clockstart.php, replace stuff and save it.

  • #10
    New Coder
    Join Date
    Mar 2013
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by patryk View Post
    i have no idea. are you getting errors?
    it looks good to me. it should take your clockstart.php, replace stuff and save it.
    Ok but how can i redirect the user to the new page?

  • #11
    Regular Coder patryk's Avatar
    Join Date
    Oct 2012
    Location
    /dev/couch
    Posts
    398
    Thanks
    2
    Thanked 64 Times in 64 Posts
    your url will be $randomString . '.php'
    so you could do redirect using header
    PHP Code:
    header("Location: http://www.example.com/directory/" $randomString '.php'); 
    or you can output link
    PHP Code:
    echo '<a href="http://www.example.com/directory/' $randomString '.php">your page is here</a>'); 

  • #12
    New Coder
    Join Date
    Mar 2013
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Smile

    Quote Originally Posted by patryk View Post
    your url will be $randomString . '.php'
    so you could do redirect using header
    PHP Code:
    header("Location: http://www.example.com/directory/" $randomString '.php'); 
    or you can output link
    PHP Code:
    echo '<a href="http://www.example.com/directory/' $randomString '.php">your page is here</a>'); 
    Thank you for the help you have given me I will always be great full to you. Thank you

  • #13
    New Coder
    Join Date
    Mar 2013
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by patryk View Post
    your url will be $randomString . '.php'
    so you could do redirect using header
    PHP Code:
    header("Location: http://www.example.com/directory/" $randomString '.php'); 
    or you can output link
    PHP Code:
    echo '<a href="http://www.example.com/directory/' $randomString '.php">your page is here</a>'); 
    But my coding program says it's a syntax error with the line you gave me

  • #14
    New Coder
    Join Date
    Mar 2013
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by sebbi99 View Post
    But my coding program says it's a syntax error with the line you gave me
    Oh i see it now you missed a ( at the start

  • #15
    New Coder
    Join Date
    Mar 2013
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by patryk View Post
    your url will be $randomString . '.php'
    so you could do redirect using header
    PHP Code:
    header("Location: http://www.example.com/directory/" $randomString '.php'); 
    or you can output link
    PHP Code:
    echo '<a href="http://www.example.com/directory/' $randomString '.php">your page is here</a>'); 
    It's only 1 problem with the code the year wont get inserted to the template everything else works?

    PHP Code:
    <?php
    $month 
    $_POST['month'];
    $days $_POST['days'];
    $year $_POST['year'];
    $time $_POST['time'];
    $dn $_POST['dn'];

    //link generator
    $length 10;

    $randomString substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0$length);

    //get template
    $template file_get_contents('clockstart.php');

    //put data in template
    $template str_replace('{imonth}'$month$template);
    $template str_replace('{iday}'$days$template);
    $template str_replace('{iyear}'$year$template);
    $template str_replace('{iclock}'$time$template);
    $template str_replace('{idn}'$dn$template);

    //save file
    file_put_contents($randomString '.php'$template);

    //The one that show the link
    echo ('<a href="http://www.slapcountdown.zxq.net/' $randomString '.php">your page is here</a>'); 
    ?>


  •  
    Page 1 of 2 12 LastLast

    Tags for this Thread

    Posting Permissions

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