Php

This is a discussion on Php within the Tech Board forums, part of the Community Boards category; Originally Posted by MisterSako i can't seem to figure out how to send POSTs between pages without it being a ...

  1. #46
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    Quote Originally Posted by MisterSako
    i can't seem to figure out how to send POSTs between pages without it being a form. can someone give me an example of a variable being sent to a page using the POST method (with out it behing a form)

    i would appreciate it

    Theres no NEED to send post variables across pages. Instead, you save the post variables in your session data, and check that data in the next page.
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  2. #47
    They Call me Mister Sako
    Join Date
    Jul 2004
    Posts
    169
    i don't get this,
    i POST to my process file so i can get the variables with $username = $_POST['username']; type of thing but i don't get why i cant just use that same thing again once it directs the user back to the registration page to have the textfields show what they last had.

    do i have to "rePOST" the variables use time i go from document to document?

    ive tried sending the user back to the register page using
    META HTTP-EQUIV=Refresh CONTENT="2; URL="
    as well as header: location
    AIM: MisterSako | MSN: sakotheinsane@hotmail.com | E-mail: klinerr1@nc.rr.com
    The goal of computer science is to be lazy

  3. #48
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    Another option is to pass it in query string.
    Code:
    $redirect_to = 'http://mysite.com/register.php?username=' + urlencode($username);
    Cookies is another, if it's appropriate at all.
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

  4. #49
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,794
    do i have to "rePOST" the variables use time i go from document to document?
    Pretty much yes. Consider using sessions.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #50
    They Call me Mister Sako
    Join Date
    Jul 2004
    Posts
    169
    i think im going to try and use cookies for this
    AIM: MisterSako | MSN: sakotheinsane@hotmail.com | E-mail: klinerr1@nc.rr.com
    The goal of computer science is to be lazy

  6. #51
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    Quote Originally Posted by MisterSako
    i think im going to try and use cookies for this

    It seems clear you are either really unclear on what sessions are all together, or you just don't get it.

    Your POST variables are ways for your users to REQUEST something of you. In order to do that, they are sending extra data to your page. Believe it or not, there is an Overhead here that while not remarkble will add up in worse case scenarios. Once a user has sent data to you once, theres absolutely no reason to continue to cary it around via request methods. Instead, you save the data in SESSIONS. Sessions stay across multiple pages and even multiple visits.

    To use sessions, it's really this simple:
    PHP Code:
    <?php
           session_start
    ();

           
    // if the user has sent us a variable via GET or POST, save it
           
    if(isset($_REQUEST['a_variable_name'])) 
                
    $_SESSION['a_variable_name'] = $_REQUEST['a_variable_name'];

    ?>
    Afterwards, on any other page in your site:
    PHP Code:
    <?php
           session_start
    ();

           
    // for some reason i want to display the form again
           // with the data they originaly sent me
          
    echo "<input type='text' name='a_variable_name' value='{$_SESSION['a_variable_name']}'/>";
    ?>

    It's really very simple.
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  7. #52
    They Call me Mister Sako
    Join Date
    Jul 2004
    Posts
    169
    i understand the purpose of sessions ive just gone crazy pulling my hair out to try and get it to work.

    on a side note does php have a limit no how long a if statement can be. i got into a weird situation where its like
    PHP Code:
    if (this){
    //10 lines of code
    } else {
    like 500 lines of code

    and the else part only has partially the stuff it should have, wihtint that 500 lines theres ?> and <?php and ?> and <?php alot of times so maybe they could be messing it up.
    AIM: MisterSako | MSN: sakotheinsane@hotmail.com | E-mail: klinerr1@nc.rr.com
    The goal of computer science is to be lazy

  8. #53
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    Quote Originally Posted by MisterSako
    i understand the purpose of sessions ive just gone crazy pulling my hair out to try and get it to work.

    on a side note does php have a limit no how long a if statement can be. i got into a weird situation where its like
    PHP Code:
    if (this){
    //10 lines of code
    } else {
    like 500 lines of code

    and the else part only has partially the stuff it should have, wihtint that 500 lines theres ?> and <?php and ?> and <?php alot of times so maybe they could be messing it up.

    No.


    For the intranet I maintain at work, I have multiple files with 1000+ each. Php is more then capable.
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  9. #54
    They Call me Mister Sako
    Join Date
    Jul 2004
    Posts
    169
    i must have some kind of oddly placed } or something
    AIM: MisterSako | MSN: sakotheinsane@hotmail.com | E-mail: klinerr1@nc.rr.com
    The goal of computer science is to be lazy

  10. #55
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    You should split your code a bit to make it more organized.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  11. #56
    They Call me Mister Sako
    Join Date
    Jul 2004
    Posts
    169
    i try to, but there is also a pointy if i have too many different php files ill eventualy be overwhelmed with a plethora of php files that are all used for one thing
    AIM: MisterSako | MSN: sakotheinsane@hotmail.com | E-mail: klinerr1@nc.rr.com
    The goal of computer science is to be lazy

  12. #57
    They Call me Mister Sako
    Join Date
    Jul 2004
    Posts
    169
    is there a alphanumeric test code that actually works?

    i want it to tell me if there are any characters in a stringbesides a-z A-z or 0-9

    i tried
    if (ereg('[^A-Za-z0-9]', $string))
    and i tried
    if (ctype_alnum($string))

    both will not work, theyre always wanting to say everything i input is alphanumeric even if its like ♠ܥ
    AIM: MisterSako | MSN: sakotheinsane@hotmail.com | E-mail: klinerr1@nc.rr.com
    The goal of computer science is to be lazy

  13. #58
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    Quote Originally Posted by MisterSako
    is there a alphanumeric test code that actually works?

    i want it to tell me if there are any characters in a stringbesides a-z A-z or 0-9

    i tried
    if (ereg('[^A-Za-z0-9]', $string))
    and i tried
    if (ctype_alnum($string))

    both will not work, theyre always wanting to say everything i input is alphanumeric even if its like ♠ܥ

    http://www.tote-taste.de/X-Project/regex/
    http://www.phpguru.org/downloads/PCR...at%20Sheet.pdf




    use http://www.quanetic.com/regex.php to test. I use it all the time. It does have a bug where you have to use double '\'s to work on special chars. so \d would be \\d
    A '^' outside means match the beginning of the string.


    what you want is /[a-zA-Z0-9]/

    also, i'd use preg_match:
    PHP Code:
         if(preg_match("/[a-zA-Z0-9]/"$str))
             echo 
    "bad input!"
    Last edited by Jeremy G; 03-07-2006 at 06:18 PM.
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  14. #59
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,794
    Actually, you might as well use ctype_alnum(), which is like C's isalnum() from <stdio.h>
    Should be faster (and somewhat simpler) than using regex, but then is literally limited to testing that each character of the whole string is indeed in the range of A-Za-z0-9

    also, i'd use preg_match:
    Unfortunately, Jeremy G, your use of preg_match() is wrong. Your pattern matches any alphanumeric character, spewing out a "bad input!" message if one is found. Correct is:
    PHP Code:
    if (preg_match('/[^A-Za-z0-9]/'$string)) {
        echo 
    "bad input!";

    EDIT:
    I see that you have tried ctype_alnum() and it didnt work. Most probably you have to do a:
    PHP Code:
    setlocale(LC_CTYPE'C'); 
    before you use ctype_alnum()
    Last edited by laserlight; 03-07-2006 at 09:10 PM.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  15. #60
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    Quote Originally Posted by laserlight
    Actually, you might as well use ctype_alnum(), which is like C's isalnum() from <stdio.h>
    Should be faster (and somewhat simpler) than using regex, but then is literally limited to testing that each character of the whole string is indeed in the range of A-Za-z0-9


    Unfortunately, Jeremy G, your use of preg_match() is wrong. Your pattern matches any alphanumeric character, spewing out a "bad input!" message if one is found. Correct is:
    PHP Code:
    if (preg_match('/[^A-Za-z0-9]/'$string)) {
        echo 
    "bad input!";

    EDIT:
    I see that you have tried ctype_alnum() and it didnt work. Most probably you have to do a:
    PHP Code:
    setlocale(LC_CTYPE'C'); 
    before you use ctype_alnum()
    It was a typo. I make mistakes.

    Every once in a while. The //'s are what i was going for.
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

Page 4 of 5 FirstFirst 12345 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. combining c php and mysql
    By Thoth in forum C Programming
    Replies: 2
    Last Post: 01-30-2009, 09:55 AM
  2. PHP installation
    By ssharish2005 in forum Tech Board
    Replies: 8
    Last Post: 11-23-2007, 08:42 PM
  3. PHP on my Computer!
    By xxxrugby in forum Tech Board
    Replies: 4
    Last Post: 03-15-2005, 08:34 AM
  4. C++ and PHP communication
    By Korhedron in forum Game Programming
    Replies: 4
    Last Post: 01-12-2004, 05:37 AM
  5. PHP 4.3.0 released
    By codingmaster in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-30-2002, 06:40 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21