I've made some progress on server.c going through the code with gdb but now I'm stuck. It seems to be working (all pages and images load "correctly" in browser) except php files. It also does not pass any of the cs50 checks (except test redirects, the folder loads hello.php, and hello.php load correctly).
Parse function was my first thought but seems to be working:
783 if(strchr(absolute_path, '?') == NULL) (gdb) p pathcopy $1 = 0x609970 "/hello.php?name=Brandon" (gdb) n 789 else if(strcmp(strchr(absolute_path, '?') + 1, "\0") == 0) (gdb) 798 query = strchr(absolute_path, '?') + 1; (gdb) 799 abs_path = strtok(pathcopy,"?"); (gdb) 802 return true; (gdb) p query $2 = 0x60796f "?name=Brandon" (gdb) p abs_path $3 = 0x609970 "/hello.php" (gdb) n 805 }
Since the browser appears correct, I assume it must be a problem with a null terminator or load. Since php also doesn't work, I'm leaning more toward how the file is loading.
Before I could use GDB and find where an error was thrown, or I knew what variables I wanted to check (eg. abs_path and query). Now my problem is my program isn't getting an error, and I don't know what variables to check (or what they should even be in the case of load).
Any guidance on where my problem might be or how to use GDB at this point would be appreciated.
Here is my code...
Update: I removed the code since it is a nearly complete working solution. Most of my errors came from small misunderstandings in how my code was operating. These errors were discovered using GDB to check variables with some of the tips DinoCoderSaurus posted below.
Another issue was how variables were transferring to different functions. Checking how the variables were reporting in different functions (using GDB) hinted that memory allocation/pointers were the issue.
In my case, these "memory" issues were fixed by mallocing sectors of memory to manipulate variables and then copying the finalized strings into the sector of memory called by the function (eg. malloc querycopy and then use strtok and other functions to manipulate it, and then transfer the result using strcpy(query,querycopy). Pointers still confuse me some, but any time I've found variable working in one function but not carrying over to the other function, pointers/memory was the issue.
May not be the best explanations but hopefully gives some insight if someone is facing similar problems.