-
Posts
293 -
Joined
-
Last visited
-
Days Won
5
jodunno last won the day on September 18
jodunno had the most liked content!
About jodunno
- Birthday 01/01/1973
Profile Information
-
Gender
Male
-
Location
Berlin, Germany
-
Interests
Nature and Biology, Programming and Web Development, Forensic Science, sports
Recent Profile Visitors
5,394 profile views
jodunno's Achievements
-
0.0 empty works. see my included code and use it in xampp. if you open an anchor tag outside of php, then close the anchor tag outside of php. because apparently the user variable is undefined and the ending anchor tag is contained within illogical php code that is not executing. <?php //$undefinedVariable = '!empty'; //$user = ''; $user = 'test'; $userhref = $user ? 'href="https://www.example.com/mycp.php"': 'href="https://www.example.com/login.php"'; $usertext = $user ? $user: 'Member Login'; ?> <ul><li class="li-btn"> <a class="custom-btn custom-btn--small custom-btn--style-4" <?php if (empty($user)){ echo 'href="https://www.example.com/login.php">Member Login'; } else { echo 'href="https://www.example.com/mycp.php">'.$user; } ?> </a> </li></ul> <ul><li class="li-btn"> <a class="custom-btn custom-btn--small custom-btn--style-4" <?php echo $userhref . '>' . $usertext; ?></a> </li></ul> <ul>Also: <li class="li-btn"> <?php echo empty($undefinedVariable) ? 'empty == true': $undefinedVariable; ?> </li> </ul> start over and think about what you are trying to accomplish. for one thing, user must mean that you have a login. How are you storing user on every page within your site? is user variable based upon a form input (post)? then one has to login on every page? one would have to login on every different page because a variable is local to the current script. You should be using a session variable or reading user from a database. Show us your code for user variable.
-
try empty(), which will supress warnings if a variable does not exist: <?php <a class="custom-btn custom-btn--small custom-btn--style-4" if (empty($user)){ echo 'href="https://www.paratuberculosis.com/login.php">Member Login</a>>'; } ?> https://www.php.net/manual/en/function.empty.php it will handle '', 0, !isset and false I assume that you are using wordpress or some other pre-coded resource You should be in control of your variables, especially user-based variables.
-
well it bothers me that you think that a full uri is a problem, so i revisit your code and voila! you have output before the header, which is an error. You must use header before any output is sent. I apologize for not noticing this error beforehand. I overlooked it yesterday. So perhaps that was your problem all along. Meantime, i have to work on reading and comprehension skills. I missed that yesterday. yikes!
-
Danke schön. Sehr nett, aber: a full uri should not be a problem. <?php session_start(); if (is_int(intval($_POST["PQty1"]))) { $_SESSION["PQty1"] = $_POST["PQty1"]; } header("Location: http://localhost/p5k/form.php"); exit; ?> you could also submit to the same page: <?php session_start(); print '<html><body> <form method="POST"> <select name="PQty1"> <option value="">Please select quantity</option>'; for ($i=1;$i<=20;$i++) { print '<option value="'.$i.'">'.$i.'</option>'; } print '</select><input type="submit" value="Add"></form>'; switch ($_SERVER['REQUEST_METHOD']) { case 'POST': if (is_int(intval($_POST["PQty1"]))) { $_SESSION["PQty1"] = $_POST["PQty1"]; } if (!empty($_SESSION["PQty1"])) { print '<p>'.$_SESSION["PQty1"].'</p>'; } break; } print '</body></html>'; ?> still, the general rule for redirection is to follow the redirection with exit. Otherwise, the script will continue executing to the end of the script. Not good if you have data after the redirection, which should not be processed. If you are happy and the script is working, then i am happy for you. I hope that you have a pleasant day, John
-
well i have changed a few things in your script which irritate me but the majority of the code is unchanged. I tested your code in xampp and i do not have any issues with the session. I have to enable cookies in Firefox or the session will not function but everything is working as expected after i enable cookies. <?php session_start(); print "<html><body> <form method=POST action=Cart1.php> <select name=PQty1> <option value=>Please select quantity</option>"; for ($i=1;$i<=20;$i++) { print "<option value=$i>$i</option>"; } print "</select><input type=submit value=Add></form>"; if (!empty($_SESSION["PQty1"])) { print "<p>".$_SESSION["PQty1"]."</p>"; } print "</body></html>"; ?> <?php session_start(); if (is_int(intval($_POST["PQty1"]))) { $_SESSION["PQty1"] = $_POST["PQty1"]; } header("Location: /p5k/form.php"); exit; ?> you have to check the local storage to see if your session cookie matches that which is sent by the server.
-
form.php start tag should be <?php you are assigning user input directly to a session variable without validating the input. I recommend casting to an integer intval() and using is_int to verify a number. or die(); will cause an error. simply exit after a header redirection: header("Location: form.php"); exit; if session cookies are not being set in the browser, then you will have empty session files (the browser will continue starting a new session). Which brings you back to the suggestions posted by requinix.
-
okay but now you need to take a closer look at your code. Specifically, not equal to. if ($_SESSION["AdmKeyy"] !== "T54") { } it seems as though your sessions may not be coded properly. Requinix is a pro and will easily be able to spot any problems. Perhaps you could post a full example of your session code.
-
and hopefully you also have session_start(); before that line of code on every individual page that needs to continue the previously started session. we cannot see your code, so we are feeling around in the dark for a flashlight...
-
I do not see a reference to a book. I find the answer to be sufficient for trouble shooting. And i will add to this: https://firefox-source-docs.mozilla.org/devtools-user/ https://developer.chrome.com/docs/devtools https://learn.microsoft.com/en-us/microsoft-edge/devtools-guide-chromium/landing/ https://developer.apple.com/library/archive/documentation/AppleApplications/Conceptual/Safari_Developer_Guide/Introduction/Introduction.html https://www.php.net/manual/en/book.session.php browser issues: disabling all cookies will include session cookies in certain browsers. clear your cache before testing. check php session file permissions, typical path is /var/lib/php/sessions check php.ini for PHP session path location: /etc/php.ini search for session.save_path in php.ini check PHP error logs: query a search engine for error log locations of your preferred web server. I also wonder what you mean by "Ubuntu only". So this problem doesn't happen in OpenSUSE or Linux Mint? or you mean that the problem is not with a Microsoft Windows system, rather a Linux based system like Ubuntu?
-
Hello Mark2024, mac_gyver has offered a good solution for you. However, you should think about persistence and start using a session to carry information site-wide/across all of your pages. Otherwise, you would have to check a database per page load/reload. You can simply check the session variable instead of using a variable with local (this script only) scope. Also, i am not criticizing or trying to change your design. Design your site as you wish. However, the font tag is deprecated and we stopped using non-breaking spaces in empty td cells many, many years ago, along with hr and 1x1 pixel gifs (although, some shady advertisers still use the 1x1 pixel gifs, LOL). Try switching to css for styling your documents and let html structure the document. <?php session_start(); //$_SESSION['loggedin'] = 0; $_SESSION['level'] = 0; $_SESSION['loggedin'] = 1; $_SESSION['level'] = 1; //admin //$_SESSION['loggedin'] = 1; $_SESSION['level'] = 0; //regular user /* number values can be trivial at times. A string with a short value is usually better. $_SESSION['level'] = (string) 'admin'; $_SESSION['level'] = (string) 'patron'; et cetera then if(!empty($_SESSION['level']) && $_SESSION['level'] === 'admin') */ ?> <html> <head> <title></title> <style type="text/css"> h3.welcome { color: yellow; } </style> </head> <body> <div id="left"> <img src="images/john.png" height="100px" width="300px" /> </div> <div id="right"> <div id="view_box"> <ul> <li><img src="images/1.png" /></li> </ul> </div> <div id="button"> <ul> <!-- <li><button class="button" scroll_value="0">*</button></li> -- > <!-- <li><button class="button" scroll_value="600">*</button></li> --> <!-- <li><button class="button" scroll_value="1200">*</button></li> --> </ul> </div> <hr /> <?php if($_SESSION['loggedin']){ ?> <h3 class="welcome">Welcome, customer_name</h3> <h3>Money That Your Due Today</h3> <table border=1"> <tr><th>FULL NAME</th><th>PURCHASE DATE</th><th>MONEY DUE</th><th>UPDATE</th></tr> <tr> <td></td> <td></td> <td></td> <td></td> </tr> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td>TOTAL DUE</td> <td>£ totmoney </td> <td></td> </tr> </table> <br /><br /><br /> <?php } else { ?> <h3>Login To Your Account</h3> <form method="post" action="login.php"> <table cellspacing="10" cellpadding="10"> <tr><td>Username</td><td><input type="text" name="username" /></td></tr> <tr><td>Password</td><td><input type="password" name="password" /></td></tr> <tr><td></td><td><input type="submit" name="submit" value="Login To Your Account" /></td></tr> </table> </form> <?php } ?> </div> <!-- <?php //include ("styles/bottom.php"); ?> --> <?php if(!empty($_SESSION['level']) && $_SESSION['level']){ echo "<a href='admin.php'>Admin Panel</a> |"; } /* or if !empty switch for multiple entries: //if(!empty($_SESSION['level'])) { //switch ($_SESSION['level']) { //case 'admin': echo "<a href='admin.php'>Admin Panel</a> |"; break; //case 'patron': echo "<a href='offers.php'>Special Offers</a> |"; break; //}} */ ?> </body></html>
-
$_SERVER['DOCUMENT_ROOT']; = server get the root path of this document which really is C:/xampp/htdocs/ switch to using root-based paths (/). require_once dirname(__FILE__) . '/dir/file.php'; / = start at root (htdocs) dir/ = enter folder named dir file.php = load this file echo '<link rel="Stylesheet" type="text/css" href="/css/styles.css" />'; / = start at root (htdocs) css/ = enter folder named css styles.css = get this file require_once dirname(__FILE__) . '/../dir/file.php'; / = start at root (htdocs) ../ = move up one dir (now outside of root) dir/ = enter folder named dir file.php = load this file
-
how to calculate a certain number of times a fraction?
jodunno replied to NikitosKnyaz's topic in PHP Coding Help
an html table is not a good idea if n > 16. Even lists surrender to the spatial demands. Here is my take on the matter. I work off of the old saying, "2 plus 2 is 4". <?php $n = (int) 5; /* $_POST['n'] from <input type="number" name="n"> */ $fourSure = function($x) { $i = $j = (int) 2; $e = array(); $e['d'] = $e['n'] = array(); for (; $x > 0; $x--) { for (; $i < $x; $i+=2, $j+=4) { $e['n'][] = $j >> 1; $e['d'][] = $i; }} return join('·', $e['n']) . ' ÷ ' . join('·', $e['d']); }; $n = $n*2+2; echo '<ul style="font-family: sans-serif; list-style-type: none;">S = '; for ($i=4; $i <= $n; $i+=2) { echo '<li>'.$fourSure($i).'</li>'; } echo '</ul>'; ?> to each his own. -
For Your Information and speaking of arrogance: "Can you solve 4 queens problem without using 2d arrays, recursion/backtracking? Just display 1 such solution." 4 queens not 8. which simply involves the 40deg connected vertices of the perimiters, which offers two immediate solutions. the pythagorean theorem affords your consciousness a visual of the process, so that you can better understand it. I guess it doesn't help. recursion and backtracking is silly and time consuming. But if you want to discuss an 8x8 matrix, then: Using the left/west side of the central 40deg diagonal as an example: we can create a (10 lines of code) loop to gather all of the diagonals and 90deg right triangles (while we're at it). attached image. However, i already have 'diagonals' stored in a vertex adjacency of ordinal directions (neighbor) array. One could easily check NW vertex, thus NW vertex loop to the N/S border. Clearing rows and columns requires no further code (if one has constructed a grid graph properly). I drink coffee.
-
Hello? you disappoint me. The code that i posted must be far over your heads. Two solutions are revealed in the code but two people here are unable to see it. LOL. Pythagorean theorem reveals diagonals (id est right angle triangles), which will place the queens in different diagonals, LOL, in different rows and columns. LOL. good lord! I feel like i'm talking to a wall. Nevermind. The concept is beyond the both of you. Carry on.... 🙂