我想要实现的目标,
one_page.php
和我们require('form.php')
,以便用户在$_SESSION['foo']
未设置时进行填充。$_SESSION['foo']
。header ('Location: one_page.php')
(实际上就像重装)if
我们unset($_SESSION['foo'])
和require('something_else.php')
。site.php
或重新输入,则他将再次获得form.php
。我不会向您展示实际的代码,因为它太大而且我不想只粘贴它的一部分,但我在下面的两个例子中重现了这个问题。
使用cookies
代码完全按预期运行。
使用session
,就像我们if
unset($_SESSION['foo'])
if
一样,然后我们离开else
并进入page1.php
。< / p>
当我在例如page2.php
设置会话并将用户重定向到<?php
if (isset($_POST['submit'])) {
setcookie('foo', 'foo', time() +3600);
header('Location: one_page.php');
}
if (isset($_COOKIE['foo'])) {
setcookie('foo', 'foo', time() -3600);
echo "We entered the IF"; //require('something_else.php')
} else {
echo "We entered the ELSE"; //require('form.php')
}
?>
<!-- The form which is required in my case -->
<html>
<body>
<form method="post">
<button name="submit">Button</button>
</form>
</body>
</html
以取消会话时,一切似乎都很好。当我在我取消设置的同一页面上创建会话时,我无法使其正常工作。
使用Cookie 当我们按下按钮时我们进入IF
<?php
session_start();
if (isset($_POST['submit'])) {
$_SESSION['foo'] = "foo";
header('Location: one_page.php');
}
if (isset($_SESSION['foo'])) {
unset($_SESSION['foo']);
echo "We entered the IF"; //require('something_else.php')
} else {
echo "We entered the ELSE"; //require('form.php')
}
?>
<!-- The form which is required in my case -->
<html>
<body>
<form method="post">
<button name="submit">Button</button>
</form>
</body>
</html>
使用会话 无论是什么
,我们都在ELSE中 java.lang.NoClassDefFoundError: Failed resolution of: Lcom/externalibrary/R$string
11-30 17:06:02.475 22610-22610/com.mycompany.myapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mycompany.myapp, PID: 22610
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/externalibrary/R$string;
at com.externalibrary.client.externalibrarySettingsManager.getShouldAnnotateBlobs(externalibrarySettingsManager.java:80)
at com.externalibrary.client.externalibrarySettingsManager.getMotionDetectorConfigurationFromPreference(externalibrarySettingsManager.java:39)
at com.externalibrary.client.externalibrarySettingsManager.getConfigurationFromPreference(externalibrarySettingsManager.java:28)
at com.externalibrary.client.externalibraryClient.<init>(externalibraryClient.java:24)
at com.mycompany.myapp.MainActivity.onCreate(MainActivity.java:191)
at android.app.Activity.performCreate(Activity.java:6664)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.externalibrary.R$string" on path: DexPathList[[zip file "/data/app/com.mycompany.myapp-2/base.apk"],nativeLibraryDirectories=[/data/app/com.mycompany.myapp-2/lib/arm, /system/fake-libs, /data/app/com.mycompany.myapp-2/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.externalibrary.client.externalibrarySettingsManager.getShouldAnnotateBlobs(externalibrarySettingsManager.java:80)
at com.externalibrary.client.externalibrarySettingsManager.getMotionDetectorConfigurationFromPreference(externalibrarySettingsManager.java:39)
at com.externalibrary.client.externalibrarySettingsManager.getConfigurationFromPreference(externalibrarySettingsManager.java:28)
at com.externalibrary.client.externalibraryClient.<init>(externalibraryClient.java:24)
at com.mycompany.myapp.MainActivity.onCreate(MainActivity.java:191)
at android.app.Activity.performCreate(Activity.java:6664)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
我可以使用cookies,但这对我来说已经好几个小时了。
有什么想法吗?
答案 0 :(得分:0)
在exit()
修复问题后添加header('Location: one_page.php')
。
Dagon说,unset($_SESSION['foo'])
在重定向之前正在运行。
<强>固定强>
<?php
session_start();
if (isset($_POST['submit'])) {
$_SESSION['foo'] = "foo";
header('Location: one_page.php');
exit();
}
if (isset($_SESSION['foo'])) {
unset($_SESSION['foo']);
echo "We entered the IF"; //require('something_else.php')
} else {
echo "We entered the ELSE"; //require('form.php')
}
?>
<!-- The form which is required in my case -->
<html>
<body>
<form method="post">
<button name="submit">Button</button>
</form>
</body>
</html>
谢谢Dagon!